home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / protocol / standard / misc / tiff_doc.0 < prev    next >
Text File  |  1993-07-14  |  179KB  |  4,687 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.           An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1          An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1
  8.           
  9.           
  10.           
  11.           Preface
  12.           
  13.           
  14.           This memorandum  has been prepared jointly by Aldus and Microsoft
  15.           in conjunction  with leading scanner vendors and other interested
  16.           parties.   This document  does not  represent a commitment on the
  17.           part of  either Microsoft  or Aldus  to provide  support for this
  18.           file format  in any  application.   When responding  to  specific
  19.           issues raised  in this memo, or when requesting additional tag or
  20.           field assignments, please address your correspondence to either:
  21.           
  22.                Developers_ Desk    Windows Marketing Group
  23.                Aldus Corporation   Microsoft Corporation
  24.                411 First Ave. South     16011 NE 36th Way
  25.                Suite 200 Box 97017
  26.                Seattle, WA  98104  Redmond, WA  98073-9717
  27.                (206) 622-5500 (206) 882-8080
  28.           
  29.           
  30.           
  31.           Revision Notes
  32.           
  33.           This revision  replaces _TIFF  Revision 4._   Sections in italics
  34.           are new or substantially changed in this revision.  Also new, but
  35.           not in italics, are Appendices F, G, and H.
  36.           
  37.           The major enhancements in TIFF 5.0 are:
  38.           
  39.           1.   Compression of  grayscale and  color images, for better disk
  40.           space utilization.  See Appendix F.
  41.           
  42.           2.   TIFF Classes_restricted  TIFF subsets  that can simplify the
  43.           job of  the TIFF  implementor.   You may  wish to scan Appendix G
  44.           before reading the rest of this document.   In fact, you may want
  45.           to use  Appendix G as your main guide, and refer back to the main
  46.           body of  the specification  as needed for details concerning TIFF
  47.           structures and field definitions.
  48.           
  49.           3.   Support for  _palette color_   images.  See the TIFF Class P
  50.           description  in   Appendix  G,   and  the   new  ColorMap   field
  51.           description.
  52.           
  53.           4.   Two new  tags that  can be  used to  more fully  define  the
  54.           characteristics of  full color  RGB data, and thereby potentially
  55.           improve the quality of color image reproduction.  See Appendix H.
  56.           
  57.           The organization  of the  document has also changed slightly.  In
  58.           particular, the  tags are  listed in  alphabetical order,  within
  59.           several categories, in the main body of the specification.
  60.           
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.           TIFF 5.0                                          page 2          TIFF 5.0                                          page 2
  71.  
  72.  
  73.           As always,  every attempt  has been  made to add functionality in
  74.           such a  way as  to minimize  incompatibility problems  with older
  75.           TIFF software.   In  particular, many  TIFF  5.0  files  will  be
  76.           readable even  by older  applications that  assume TIFF 4.0 or an
  77.           earlier version  of the  specification.   One exception  is  with
  78.           files that  use the  new TIFF  5.0 LZW  compression scheme.   Old
  79.           applications will  have to  give up  in this case, of course, and
  80.           will do so _gracefully_ if they have been following the rules.
  81.           
  82.           We  are  grateful  to  all  of  the  draft  reviewers  for  their
  83.           suggestions.   Especially helpful  were Herb  Weiner  of  Kitchen
  84.           Wisdom  Publishing   Company,  Brad  Pillow  of  TrueVision,  and
  85.           engineers from Hewlett Packard and Quark.  Chris Sears of Magenta
  86.           Graphics provided information which is included as Appendix H.
  87.           
  88.           
  89.           Abstract
  90.           
  91.           This document  describes TIFF,  a tag  based file  format that is
  92.           designed to promote the interchange of digital image data.
  93.           
  94.           The fields  were defined  primarily with  desktop publishing  and
  95.           related applications  in mind, although it is possible that other
  96.           sorts of imaging applications may find TIFF to be useful.
  97.           
  98.           The general  scenario for  which TIFF  was invented  assumes that
  99.           applications software  for scanning  or painting  creates a  TIFF
  100.           file, which  can then  be read and incorporated into a _document_
  101.           or _publication_   by an application such as a desktop publishing
  102.           package.
  103.           
  104.           TIFF is  not a printer language or page description language, nor
  105.           is it intended to be a general document interchange standard. The
  106.           primary design  goal was  to provide  a rich  environment  within
  107.           which the exchange of image data between application programs can
  108.           be accomplished.   This  richness is  required in  order to  take
  109.           advantage of  the varying  capabilities of  scanners and  similar
  110.           devices.  TIFF is therefore designed to be a superset of existing
  111.           image file  formats for  _desktop_   scanners (and paint programs
  112.           and anything  else that  produces images with pixels in them) and
  113.           will be enhanced on a continuing basis as new capabilities arise.
  114.           A high  priority has been given to structuring the data in such a
  115.           way as  to minimize  the pain  of future  additions.    TIFF  was
  116.           designed to be an extensible interchange format.
  117.           
  118.           Although TIFF  is claimed  to be  in some sense a rich format, it
  119.           can easily  be used for simple scanners and applications as well,
  120.           since the  application developer  need only be concerned with the
  121.           capabilities that he requires.
  122.           
  123.           TIFF is intended to be independent of specific operating systems,
  124.           filing systems,  compilers, and processors.  The only significant
  125.           assumption is  that the  storage medium supports something like a
  126.           _file,_   defined as  a sequence  of 8-bit bytes, where the bytes
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.           TIFF 5.0                                          page 3          TIFF 5.0                                          page 3
  137.  
  138.  
  139.           are numbered  from 0  to N.   The  largest possible  TIFF file is
  140.           2**32 bytes  in length.   Since TIFF uses pointers (byte offsets)
  141.           quite liberally,  a TIFF  file is  most easily read from a random
  142.           access device  such as a hard disk or flexible diskette, although
  143.           it should  be possible  to read  and write TIFF files on magnetic
  144.           tape.
  145.           
  146.           The recommended  MS-DOS, UNIX,  and OS/2  file extension for TIFF
  147.           files is  _.TIF._   The recommended Macintosh filetype is _TIFF_.
  148.           Suggestions for  conventions in  other computing environments are
  149.           welcome.
  150.           
  151.           
  152.           1) Structure
  153.           
  154.           In TIFF, individual fields are identified with a unique tag. This
  155.           allows particular fields to be present or absent from the file as
  156.           required by the application.  For an explanation of the rationale
  157.           behind using a tag structure format, see Appendix A.
  158.           
  159.           A TIFF file begins with an 8-byte _image file header_ that points
  160.           to one  or  more  _image  file  directories._    The  image  file
  161.           directories contain  information about  the images,  as  well  as
  162.           pointers to the actual image data.
  163.           
  164.           See Figure 1.
  165.           
  166.           We will now describe these structures in more detail.
  167.           
  168.           Image file header
  169.           
  170.           A TIFF  file begins  with an 8-byte image file header, containing
  171.           the following information:
  172.           
  173.           Bytes 0-1:     The first  word of  the file  specifies  the  byte
  174.           order used within the file.  Legal values are:
  175.           
  176.                     _II_ (hex 4949)
  177.                     _MM_ (hex 4D4D)
  178.           
  179.                In the  _II_   format,  byte  order  is  always  from  least
  180.           significant to  most significant,  for  both  16-bit  and  32-bit
  181.           integers.   In the  _MM_   format, byte order is always from most
  182.           significant to  least significant,  for both  16-bit  and  32-bit
  183.           integers.   In both  formats, character  strings are  stored into
  184.           sequential byte locations.
  185.           
  186.                All  TIFF   readers  should  support  both  byte  orders_see
  187.           Appendix G.
  188.           
  189.           Bytes 2-3 The second  word of  the  file  is  the  TIFF  _version
  190.           number._   This number, 42 (2A in hex), is not to be equated with
  191.           the current  Revision of  the TIFF  specification.   In fact, the
  192.           TIFF version  number (42)  has never  changed, and probably never
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.           TIFF 5.0                                          page 4          TIFF 5.0                                          page 4
  203.  
  204.  
  205.           will.   If it  ever does,  it means that TIFF has changed in some
  206.           way so  radical that  a TIFF  reader should  give up immediately.
  207.           The number 42 was chosen for its deep philosophical significance.
  208.           It can and should be used as additional verification that this is
  209.           indeed a TIFF file.
  210.           
  211.                A TIFF  file does  not have  a real version/revision number.
  212.           This was  an explicit,  conscious design  decision.  In many file
  213.           formats, fields  take on different meanings depending on a single
  214.           version number.   The  problem is that as the file format _ages,_
  215.           it becomes  increasingly difficult  to document which fields mean
  216.           what in  a given  version, and older software usually has to give
  217.           up if  it encounters  a file  with a  newer version  number.   We
  218.           wanted TIFF  fields to have a permanent and well-defined meaning,
  219.           so that  _older_ software  can usually  read _newer_  TIFF files.
  220.           The bottom line is lower software release costs and more reliable
  221.           software.
  222.           
  223.           Bytes 4-7 This long  word contains  the offset  (in bytes) of the
  224.           first Image File Directory.  The directory may be at any location
  225.           in the  file after  the header but must begin on a word boundary.
  226.           In particular,  an Image File Directory may follow the image data
  227.           it describes.   Readers must simply follow the pointers, wherever
  228.           they may lead.
  229.           
  230.                (The term  _byte offset_  is always used in this document to
  231.           refer to  a location  with respect  to the beginning of the file.
  232.           The first byte of the file has an offset of 0.)
  233.           
  234.           
  235.           Image file directory
  236.           
  237.           An Image  File Directory  (IFD) consists of a 2-byte count of the
  238.           number of  entries (i.e.,  the number  of fields),  followed by a
  239.           sequence of 12-byte field entries, followed by a 4-byte offset of
  240.           the next  Image File  Directory (or 0 if none).  Do not forget to
  241.           write the 4 bytes of 0 after the last IFD.
  242.           
  243.           Each 12-byte IFD entry has the following format:
  244.           
  245.           Bytes 0-1 contain the Tag for the field.
  246.           Bytes 2-3 contain the field Type.
  247.           Bytes 4-7 contain the  Length (_Count_  might have  been a better
  248.           term) of the field.
  249.           Bytes 8-11     contain the  Value Offset,  the  file  offset  (in
  250.           bytes) of  the Value  for the  field.   The Value  is expected to
  251.           begin on  a word  boundary; the  corresponding Value  Offset will
  252.           thus be  an even  number.  This file offset may point to anywhere
  253.           in the file, including after the image data.
  254.           
  255.           The entries  in an  IFD must be sorted in ascending order by Tag.
  256.           Note that this is not the order in which the fields are described
  257.           in this  document.   For a  numerically ordered list of tags, see
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.           TIFF 5.0                                          page 5          TIFF 5.0                                          page 5
  269.  
  270.  
  271.           Appendix E.  The Values to which directory entries point need not
  272.           be in any particular order in the file.
  273.           
  274.           In order  to save time and space, the Value Offset is interpreted
  275.           to contain  the Value  instead of  pointing to  the Value  if the
  276.           Value fits  into 4  bytes.  If the Value is less than 4 bytes, it
  277.           is left-justified within the 4-byte Value Offset, i.e., stored in
  278.           the lower-numbered bytes.  Whether or not the Value fits within 4
  279.           bytes is  determined by  looking at  the Type  and Length  of the
  280.           field.
  281.           
  282.           The Length  is specified in terms of the data type, not the total
  283.           number of bytes.  A single 16-bit word (SHORT) has a Length of 1,
  284.           not 2,  for example.   The  data  types  and  their  lengths  are
  285.           described below:
  286.           
  287.           1 = BYTE  An 8-bit unsigned integer.
  288.           2 = ASCII 8-bit bytes  that store ASCII codes; the last byte must
  289.           be null.
  290.           3 = SHORT A 16-bit (2-byte) unsigned integer.
  291.           4 = LONG  A 32-bit (4-byte) unsigned integer.
  292.           5 = RATIONAL   Two LONG_s:  the first represents the numerator of
  293.           a fraction, the second the denominator.
  294.           
  295.           The value of the Length part of an ASCII field entry includes the
  296.           null.   If padding  is necessary, the Length does not include the
  297.           pad byte.   Note  that there  is no  _count byte,_ as there is in
  298.           Pascal-type strings.   The Length part of the field takes care of
  299.           that.   The null  is not  strictly necessary, but may make things
  300.           slightly simpler for C programmers.
  301.           
  302.           The reader  should check  the type  to ensure  that it is what he
  303.           expects.   TIFF currently  allows more than 1 valid type for some
  304.           fields.   For example,  ImageWidth and ImageLength were specified
  305.           as having  type SHORT.  Very large images with more than 64K rows
  306.           or columns  are possible with some devices even now.  Rather than
  307.           add parallel  LONG tags  for these fields, it is cleaner to allow
  308.           both SHORT  and LONG  for ImageWidth  and similar  fields.    See
  309.           Appendix G for specific recommendations.
  310.           
  311.           Note that  there may  be more  than one IFD.  Each IFD is said to
  312.           define a _subfile._   One potential use of subsequent subfiles is
  313.           to describe  a _sub-image_   that  is somehow related to the main
  314.           image, such as a reduced resolution version of the image.
  315.           
  316.           If you have not already done so, you may wish to turn to Appendix
  317.           G to study the sample TIFF images.
  318.           
  319.           
  320.           2) Definitions
  321.           
  322.           Note that the TIFF structure as described in the previous section
  323.           is not  specific to  imaging applications in any way.  It is only
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.           TIFF 5.0                                          page 6          TIFF 5.0                                          page 6
  335.  
  336.  
  337.           the definitions of the fields themselves that jointly describe an
  338.           image.
  339.           
  340.           Before we  begin defining  the fields,  we will define some basic
  341.           concepts.   An image  is defined  to be  a rectangular  array  of
  342.           _pixels,_  each of which consists of one or more _samples._  With
  343.           monochromatic data,  we have  one sample  per pixel, and _sample_
  344.           and _pixel_   can  be  used  interchangeably.    RGB  color  data
  345.           contains three samples per pixel.
  346.           
  347.           
  348.           3) The Fields
  349.           
  350.           This section  describes the  fields defined  in this  version  of
  351.           TIFF.   More fields  may be  added in future versions_if possible
  352.           they will  be added in such a way so as not to break old software
  353.           that encounters a newer TIFF file.
  354.           
  355.           The documentation  for each  field contains the name of the field
  356.           (quite arbitrary, but convenient), the Tag value, the field Type,
  357.           the Number of Values (N) expected, comments describing the field,
  358.           and the  default, if  any.  Readers must assume the default value
  359.           if the field does not exist.
  360.           
  361.           _No default_  does not  mean that  a TIFF  writer should  not pay
  362.           attention to  the tag.  It simply means that there is no default.
  363.           If the  writer has reason to believe that readers will care about
  364.           the value  of this  field, the writer should write the field with
  365.           the appropriate value.  TIFF readers can do whatever they want if
  366.           they encounter a missing _no default_ field that they care about,
  367.           short of  refusing to  import the file.  For example, if a writer
  368.           does  not  write  out  a  PhotometricInterpretation  field,  some
  369.           applications will  interpret the  image _correctly,_  and  others
  370.           will display  the image  inverted.  This is not a good situation,
  371.           and writers should be careful not to let it happen.
  372.           
  373.           The  fields   are  grouped   into  several  categories:    basic,
  374.           informational, facsimile,  document storage and retrieval, and no
  375.           longer recommended.   A  future version  of the specification may
  376.           pull some of these categories into separate companion documents.
  377.           
  378.           Many fields  are described  in this  document, but  most are  not
  379.           _required._   See Appendix  G for  a list  of required fields, as
  380.           well as  examples of  how to combine fields into valid and useful
  381.           TIFF files.
  382.           Basic Fields
  383.           
  384.           
  385.           Basic fields  are  fields  that  are  fundamental  to  the  pixel
  386.           architecture or visual characteristics of an image.
  387.           
  388.           BitsPerSample
  389.           Tag  = 258  (102)
  390.           Type = SHORT
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.           TIFF 5.0                                          page 7          TIFF 5.0                                          page 7
  401.  
  402.  
  403.           N    = SamplesPerPixel
  404.           
  405.           Number of bits per sample.  Note that this tag allows a different
  406.           number of  bits per  sample for  each sample  corresponding to  a
  407.           pixel.   For example, RGB color data could use a different number
  408.           of bits  per sample for each of the three color planes.  Most RGB
  409.           files will have the same number of BitsPerSample for each sample.
  410.           Even in this case, be sure to include all three entries.  Writing
  411.           _8_ when you mean _8,8,8_ sets a bad precedent for other fields.
  412.           
  413.           Default = 1.  See also SamplesPerPixel.
  414.           
  415.           
  416.           ColorMap
  417.           Tag  = 320 (140)
  418.           Type = SHORT
  419.           N    = 3 * (2**BitsPerSample)
  420.           
  421.           This tag  defines a  Red-Green-Blue color  map for  palette color
  422.           images.   The palette color pixel value is used to index into all
  423.           3 subcurves.   For  example, a Palette color pixel having a value
  424.           of 0  would be  displayed according  to the 0th entry of the Red,
  425.           Green, and Blue subcurves.
  426.           
  427.           The subcurves  are stored  sequentially.   The Red  entries  come
  428.           first, followed  by the  Green  entries,  followed  by  the  Blue
  429.           entries.   The length  of each  subcurve is  2**BitsPerSample.  A
  430.           ColorMap entry  for an  8-bit Palette color image would therefore
  431.           have 3  * 256  entries.   The width  of each entry is 16 bits, as
  432.           implied  by  the  type  of  SHORT.    0  represents  the  minimum
  433.           intensity, and  65535 represents the maximum intensity.  Black is
  434.           represented by  0,0,0, and  white by  65535, 65535,  65535.   The
  435.           purpose of  the color  map is to act as a _lookup_  table mapping
  436.           pixel values from 0 to 2**BitsPerSample-1 into RGB triplets.
  437.           
  438.           The ColorResponseCurves  field may  be used  in conjunction  with
  439.           ColorMap to further refine the meaning of the RGB triplets in the
  440.           ColorMap.   However, the  ColorResponseCurves default  should  be
  441.           sufficient in most cases.
  442.           
  443.           See also PhotometricInterpretation_palette color.
  444.           
  445.           No default.   ColorMap  must be  included in  all  palette  color
  446.           images.
  447.           
  448.           
  449.           ColorResponseCurves
  450.           Tag  = 301 (12D)
  451.           Type = SHORT
  452.           N    = 3 * (2**BitsPerSample)
  453.           
  454.           This tag  defines three  color response curves, one each for Red,
  455.           Green and  Blue color  information.   The Red entries come first,
  456.           followed by the Green entries, followed by the Blue entries.  The
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.           TIFF 5.0                                          page 8          TIFF 5.0                                          page 8
  467.  
  468.  
  469.           length  of   each  subcurve   is  2**BitsPerSample,   using   the
  470.           BitsPerSample value corresponding to the respective primary.  The
  471.           width of  each entry is 16 bits, as implied by the type of SHORT.
  472.           0 represents  the minimum  intensity, and  65535  represents  the
  473.           maximum intensity.   Black  is represented by 0,0,0, and white by
  474.           65535, 65535,  65535.   Therefore, a ColorResponseCurve entry for
  475.           RGB data  where each of the samples is 8 bits deep would have 3 *
  476.           256 entries, each consisting of a SHORT.
  477.           
  478.           The purpose of the color response curves is to refine the content
  479.           of RGB color images.
  480.           
  481.           See Appendix H, section VII, for further information.
  482.           
  483.           Default:  curves based on the NTSC recommended gamma of 2.2.
  484.           
  485.           
  486.           Compression
  487.           Tag  = 259  (103)
  488.           Type = SHORT
  489.           N    = 1
  490.           
  491.           1 =  No compression,  but pack  data into  bytes  as  tightly  as
  492.           possible, with  no unused  bits except  at the end of a row.  The
  493.           bytes are  stored as  an array of type BYTE, for BitsPerSample <=
  494.           8,  SHORT   if  BitsPerSample   >  8  and  <=  16,  and  LONG  if
  495.           BitsPerSample >  16 and <= 32.  The byte ordering of data >8 bits
  496.           must be  consistent with  that specified  in the TIFF file header
  497.           (bytes 0  and 1).   _II_    format  files  will  have  the  least
  498.           significant bytes  preceeding the  most significant  bytes  while
  499.           _MM_  format files will have the opposite.
  500.           
  501.                If the  number of  bits per  sample is not a power of 2, and
  502.           you are willing to give up some space for better performance, you
  503.           may wish to use the next higher power of 2.  For example, if your
  504.           data can  be represented  in 6 bits, you may wish to specify that
  505.           it is 8 bits deep.
  506.           
  507.                Rows are  required to  begin on byte boundaries.  The number
  508.           of bytes  per row  is therefore  (ImageWidth *  SamplesPerPixel *
  509.           BitsPerSample  +   7)  /  8,  assuming  integer  arithmetic,  for
  510.           PlanarConfiguration=1.     Bytes  per   row  is   (ImageWidth   *
  511.           BitsPerSample + 7) / 8 for PlanarConfiguration=2.
  512.           
  513.                Some graphics  systems want rows to be word- or double-word-
  514.           aligned.   Uncompressed TIFF  rows will  need to  be copied  into
  515.           word- or  double-word-padded row  buffers before  being passed to
  516.           the graphics routines in these environments.
  517.           
  518.           2 =  CCITT Group  3 1-Dimensional  Modified  Huffman  run  length
  519.           encoding.   See Appendix  B:   _Data Compression  --  Scheme  2._
  520.           BitsPerSample must  be 1,  since  this  type  of  compression  is
  521.           defined only for bilevel images.
  522.           
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.           TIFF 5.0                                          page 9          TIFF 5.0                                          page 9
  533.  
  534.  
  535.                When  you  decompress  data  that  has  been  compressed  by
  536.           Compression=2, you  must translate  white runs into 0_s and black
  537.           runs into  1_s.   Therefore, the normal PhotometricInterpretation
  538.           for those  compression types  is 0  (WhiteIsZero).   If a  reader
  539.           encounters a  PhotometricInterpretation of  1  (BlackIsZero)  for
  540.           such an  image, the  image should  be displayed  and printed with
  541.           black and white reversed.
  542.           
  543.           5 = LZW Compression,  for grayscale, mapped color, and full color
  544.           images.  See Appendix F.
  545.           
  546.           32773 =  PackBits compression,  a simple byte oriented run length
  547.           scheme for 1-bit images.  See Appendix C.
  548.           
  549.           Data compression only applies to raster image data, as pointed to
  550.           by StripOffsets.  All other TIFF information is unaffected.
  551.           
  552.           Default = 1.
  553.           
  554.           
  555.           GrayResponseCurve
  556.           Tag  = 291 (123)
  557.           Type = SHORT
  558.           N    = 2**BitsPerSample
  559.           
  560.           The purpose  of the  gray response curve and the gray units is to
  561.           provide more  exact photometric  interpretation  information  for
  562.           gray scale image data, in terms of optical density.
  563.           
  564.           The  GrayScaleResponseUnits   specifies  the   accuracy  of   the
  565.           information contained  in the  curve.   Since optical  density is
  566.           specified in  terms of  fractional numbers, this tag is necessary
  567.           to know  how to  interpret the  stored integer  information.  For
  568.           example, if  GrayScaleResponseUnits is  set to 4 (ten-thousandths
  569.           of a  unit), and a GrayScaleResponseCurve number for gray level 4
  570.           is 3455,  then the  resulting actual  value is  0.3455.   Optical
  571.           densitometers typically measure densities within the range of 0.0
  572.           to 2.0.
  573.           
  574.           If the  gray scale  response curve  is known  for the data in the
  575.           TIFF file, and if the gray scale response of the output device is
  576.           known, then  an intelligent  conversion can  be made  between the
  577.           input data and the output device.  For example, the output can be
  578.           made to  look just  like the  input.   In addition,  if the input
  579.           image lacks  contrast (as  can be  seen from the response curve),
  580.           then appropriate contrast enhancements can be made.
  581.           
  582.           The purpose  of the  gray scale  response curve  is to  act as  a
  583.           _lookup_   table mapping values from 0 to 2**BitsPerSample-1 into
  584.           specific   density    values.      The   0th   element   of   the
  585.           GrayResponseCurve array  is used to define the gray value for all
  586.           pixels  having   a  value   of  0,   the  1st   element  of   the
  587.           GrayResponseCurve array  is used to define the gray value for all
  588.           pixels having  a value of 1, and so on, up to 2**BitsPerSample-1.
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.           TIFF 5.0                                          page 10          TIFF 5.0                                          page 10
  599.  
  600.  
  601.           If your  data is  _really,_ say, 7-bit data, but you are adding a
  602.           1-bit pad  to each  pixel to  turn it into 8-bit data, everything
  603.           still works:   If  the data is high-order justified, half of your
  604.           GrayResponseCurve entries  (the odd ones, probably) will never be
  605.           used, but  that doesn_t  hurt anything.  If the data is low-order
  606.           justified, your  pixel values  will be between 0 and 127, so make
  607.           your GrayResponseCurve  accordingly.   What your  curve does from
  608.           128 to  255 doesnÆt matter.  Note that low-order justification is
  609.           probably not  a good  idea, however,  since not  all applications
  610.           look at GrayResponseCurve.  Note also that LZW compression yields
  611.           the same  compression ratio  regardless of  whether the  data  is
  612.           high-order or low-order justified.
  613.           
  614.           It is  permissable to  have a  GrayResponseCurve even for bilevel
  615.           (1-bit) images.   The  GrayResponseCurve will  have 2 values.  It
  616.           should be noted, however, that TIFF B readers are not required to
  617.           pay attention  to  GrayResponseCurves  in  TIFF  B  files.    See
  618.           Appendix G.
  619.           
  620.           If both  GrayResponseCurve and  PhotometricInterpretation  fields
  621.           exist  in   the  IFD,   GrayResponseCurve  values   override  the
  622.           PhotometricInterpretation value.   But it is a good idea to write
  623.           out both, since some applications do not yet pay attention to the
  624.           GrayResponseCurve.
  625.           
  626.           Writers may  wish to  purchase a  Kodak Reflection Density Guide,
  627.           catalog number  146 5947,  available for  $10 or  so at  prepress
  628.           supply houses,  to help them figure out reasonable density values
  629.           for their scanner or frame grabber.  If that sounds like too much
  630.           work,   we    recommend   a    curve   that    is    linear    in
  631.           intensity/reflectance.  To compute reflectance from density:  R =
  632.           1 /  pow(10,D).   To compute  density from reflectance: D = log10
  633.           (1/R).   A typical  4-bit GrayResponseCurve  may  look  therefore
  634.           something like:   2000,  1177, 875, 699, 574, 477, 398, 331, 273,
  635.           222, 176,  135, 97, 62, 30, 0, assuming GrayResponseUnit=3.  Such
  636.           a curve would be consistent with PhotometricInterpretation=1.
  637.           
  638.           See also GrayResponseUnit, PhotometricInterpretation, ColorMap.
  639.           
  640.           
  641.           GrayResponseUnit
  642.           Tag  = 290 (122)
  643.           Type = SHORT
  644.           N    = 1
  645.           
  646.           1 = Number represents tenths of a unit.
  647.           2 = Number represents hundredths of a unit.
  648.           3 = Number represents thousandths of a unit.
  649.           4 = Number represents ten-thousandths of a unit.
  650.           5 = Number represents hundred-thousandths of a unit.
  651.           
  652.           Modifies GrayResponseCurve.
  653.           
  654.           See also GrayResponseCurve.
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.           TIFF 5.0                                          page 11          TIFF 5.0                                          page 11
  665.  
  666.  
  667.           
  668.           For historical  reasons, the  default is 2.  However, for greater
  669.           accuracy, we recommend using 3.
  670.           
  671.           
  672.           ImageLength
  673.           Tag  = 257  (101)
  674.           Type = SHORT or LONG
  675.           N    = 1
  676.           
  677.           The image_s  length (height) in pixels (Y: vertical).  The number
  678.           of rows  (sometimes described as _scan lines") in the image.  See
  679.           also ImageWidth.
  680.           
  681.           No default.
  682.           
  683.           
  684.           ImageWidth
  685.           Tag  = 256  (100)
  686.           Type = SHORT or LONG
  687.           N    = 1
  688.           
  689.           The image_s  width, in  pixels (X:  horizontal).   The number  of
  690.           columns in the image.  See also ImageLength.
  691.           
  692.           No default.
  693.           
  694.           
  695.           NewSubfileType
  696.           Tag =  254  (FE)
  697.           Type = LONG
  698.           N = 1
  699.           
  700.           Replaces the  old SubfileType  field, due  to limitations  in the
  701.           definition of that field.
  702.           
  703.           A general  indication of  the kind  of data  that is contained in
  704.           this subfile.   This  field is  made up of a set of 32 flag bits.
  705.           Unused bits are expected to be 0.  Bit 0 is the low-order bit.
  706.           
  707.           Currently defined values are:
  708.           
  709.           Bit 0     is 1  if the  image is  a reduced resolution version of
  710.           another image in this TIFF file; else the bit is 0.
  711.           Bit 1     is 1  if the  image is  a single  page of  a multi-page
  712.           image (see the PageNumber tag description); else the bit is 0.
  713.           Bit 2     is 1  if the  image defines  a  transparency  mask  for
  714.           another image  in this  TIFF file.  The PhotometricInterpretation
  715.           value must be 4, designating a transparency mask.
  716.           
  717.           These values  have been  defined as  bit flags  because they  are
  718.           pretty much independent of each other.  For example, it be useful
  719.           to have  four images  in a  single TIFF  file: a  full resolution
  720.           image, a  reduced resolution  image, a  transparency mask for the
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.           TIFF 5.0                                          page 12          TIFF 5.0                                          page 12
  731.  
  732.  
  733.           full resolution  image, and  a transparency  mask for the reduced
  734.           resolution image.  Each of the four images would have a different
  735.           value for the NewSubfileType field.
  736.           
  737.           Default is 0.
  738.           
  739.           
  740.           PhotometricInterpretation
  741.           Tag  = 262  (106)
  742.           Type = SHORT
  743.           N    = 1
  744.           
  745.           0 =  For bilevel  and grayscale  images:   0 is  imaged as white.
  746.           2**BitsPerSample-1 is  imaged as  black.    If  GrayResponseCurve
  747.           exists,  it   overrides  the   PhotometricInterpretation   value,
  748.           although  it  is  safer  to  make  them  match,  since  some  old
  749.           applications may still be ignoring GrayResponseCurve. This is the
  750.           normal value for Compression=2.
  751.           
  752.           1 =  For bilevel  and grayscale  images:   0 is  imaged as black.
  753.           2**BitsPerSample-1  is  imaged  as  white.  If  GrayResponseCurve
  754.           exists,  it   overrides  the   PhotometricInterpretation   value,
  755.           although  it  is  safer  to  make  them  match,  since  some  old
  756.           applications may  still be  ignoring GrayResponseCurve.  If  this
  757.           value is  specified for  Compression=2, the  image should display
  758.           and print reversed.
  759.           
  760.           2 = RGB.  In the RGB model, a color is described as a combination
  761.           of the  three primary  colors of  light (red, green, and blue) in
  762.           particular concentrations.   For  each of  the three  samples,  0
  763.           represents minimum intensity, and 2**BitsPerSample - 1 represents
  764.           maximum intensity.   Thus  an RGB  value  of  (0,0,0)  represents
  765.           black,  and   (255,255,255)  represents   white,  assuming  8-bit
  766.           samples.   For PlanarConfiguration = 1, the samples are stored in
  767.           the indicated  order:   first Red,  then Green,  then Blue.   For
  768.           PlanarConfiguration =  2, the  StripOffsets for the sample planes
  769.           are stored  in the  indicated order:   first the Red sample plane
  770.           StripOffsets, then  the Green  plane StripOffsets,  then the Blue
  771.           plane StripOffsets.
  772.           
  773.                The ColorResponseCurves field may be used to globally refine
  774.           or alter  the color  balance of  an RGB  image without  having to
  775.           change the values of the pixels themselves.
  776.           
  777.           3="Palette color._     In this  mode, a color is described with a
  778.           single sample.   The  sample is  used as  an index into ColorMap.
  779.           The sample  is used to index into each of the red, green and blue
  780.           curve tables to retrieve an RGB triplet defining an actual color.
  781.           When this  PhotometricInterpretation value  is  used,  the  color
  782.           response curves  must also  be supplied.  SamplesPerPixel must be
  783.           1.
  784.           
  785.           4 =  Transparency Mask.   This  means that  the image  is used to
  786.           define an  irregularly shaped region of another image in the same
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.           TIFF 5.0                                          page 13          TIFF 5.0                                          page 13
  797.  
  798.  
  799.           TIFF  file.     SamplesPerPixel  and  BitsPerSample  must  be  1.
  800.           PackBits compression  is recommended.    The  1-bits  define  the
  801.           interior of  the region;  the 0-bits  define the  exterior of the
  802.           region.  The Transparency Mask must have the same ImageLength and
  803.           ImageWidth as the main image.
  804.           
  805.                A reader  application can  use the  mask to  determine which
  806.           parts of the image to display.  Main image pixels that correspond
  807.           to 1-bits  in the  transparency mask  are imaged to the screen or
  808.           printer, but  main image  pixels that correspond to 0-bits in the
  809.           mask are not displayed or printed.
  810.           
  811.                It is  possible to  generalize the  notion of a transparency
  812.           mask to  include partial  transparency, but  it is not clear that
  813.           such information would be useful to a desktop publishing program.
  814.           
  815.           No default.   That  means that  if you  care  if  your  image  is
  816.           displayed and  printed as  _normal_ vs _inverted,_ you must write
  817.           out this  field.   Do not rely on applications defaulting to what
  818.           you want!   PhotometricInterpretation  =  1  is  recommended  for
  819.           bilevel (except  for Compression=2)  and grayscale images, due to
  820.           popular user  interfaces for changing the brightness and contrast
  821.           of images.
  822.           
  823.           
  824.           PlanarConfiguration
  825.           Tag  = 284  (11C)
  826.           Type = SHORT
  827.           N    = 1
  828.           
  829.           1 =  The sample values for each pixel are stored contiguously, so
  830.           that   there    is   a    single   image    plane.            See
  831.           PhotometricInterpretation to  determine the  order of the samples
  832.           within the  pixel data.   So,  for RGB  data, the  data is stored
  833.           RGBRGBRGB...and so on.
  834.           
  835.           2 =  The samples  are stored  in separate  _sample planes._   The
  836.           values in StripOffsets and StripByteCounts are then arranged as a
  837.           2-dimensional array, with SamplesPerPixel rows and StripsPerImage
  838.           columns.      (All of  the columns  for row  0 are  stored first,
  839.           followed   by    the   columns    of   row   1,   and   so   on.)
  840.           PhotometricInterpretation describes  the type  of  data  that  is
  841.           stored in  each sample  plane.   For example,  RGB data is stored
  842.           with the  Red samples  in one sample plane, the Green in another,
  843.           and the Blue in another.
  844.           
  845.           If SamplesPerPixel  is 1,  PlanarConfiguration is irrelevant, and
  846.           should not be included.
  847.           Default is 1.  See also BitsPerSample, SamplesPerPixel.
  848.           
  849.           
  850.           Predictor
  851.           Tag  = 317 (13D)
  852.           Type = SHORT
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.           TIFF 5.0                                          page 14          TIFF 5.0                                          page 14
  863.  
  864.  
  865.           N    = 1
  866.           
  867.           To be used when Compression=5 (LZW).  See Appendix F.
  868.           
  869.           1 = No prediction scheme used before coding.
  870.           
  871.           Default is 1.
  872.           
  873.           
  874.           ResolutionUnit
  875.           Tag  = 296 (128)
  876.           Type = SHORT
  877.           N    = 1
  878.           
  879.           To be used with XResolution and YResolution.
  880.           
  881.           1 =  No absolute  unit of  measurement.  Used for images that may
  882.           have a  non-square  aspect  ratio,  but  no  meaningful  absolute
  883.           dimensions.   The drawback  of ResolutionUnit=1 is that different
  884.           applications will  import the  image at different sizes.  Even if
  885.           the decision  is quite  arbitrary, it might be better to use dots
  886.           per inch  or  dots  per  centimeter,  and  pick  XResolution  and
  887.           YResolution such that the aspect ratio is correct and the maximum
  888.           dimension of  the image is about four inches (the _four_ is quite
  889.           arbitrary.)
  890.           2 = Inch.
  891.           3 = Centimeter.
  892.           
  893.           Default is 2.  See also XResolution, YResolution.
  894.           
  895.           
  896.           RowsPerStrip
  897.           Tag  = 278  (116)
  898.           Type = SHORT or LONG
  899.           N    = 1
  900.           
  901.           The number  of rows  per strip.  The image data is organized into
  902.           strips for  fast access  to individual  rows  when  the  data  is
  903.           compressed_though this  field is  valid even  if the  data is not
  904.           compressed.
  905.           
  906.           RowsPerStrip and  ImageLength together  tell  us  the  number  of
  907.           strips in  the entire  image.   The equation  is StripsPerImage =
  908.           (ImageLength + RowsPerStrip - 1) / RowsPerStrip, assuming integer
  909.           arithmetic.
  910.           
  911.           Note that  either SHORT  or LONG  values can  be used  to specify
  912.           RowsPerStrip.   SHORT values  may be  used for  small TIFF files.
  913.           It should  be noted,  however, that  earlier  TIFF  specification
  914.           revisions required  LONG values  and that  some software  may not
  915.           expect SHORT values.  See Appendix G for further recommendations.
  916.           
  917.           Default is  2**32 -  1, which  is effectively infinity.  That is,
  918.           the entire  image is  one strip.   We  do not  recommend a single
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.           TIFF 5.0                                          page 15          TIFF 5.0                                          page 15
  929.  
  930.  
  931.           strip, however.   Choose  RowsPerStrip such  that each  strip  is
  932.           about 8K  bytes, even  if the  data is  not compressed,  since it
  933.           makes buffering  simpler for  readers.   The _8K_  part is pretty
  934.           arbitrary, but seems to work well.
  935.           
  936.           See also ImageLength, StripOffsets, StripByteCounts.
  937.           
  938.           
  939.           SamplesPerPixel
  940.           Tag  = 277  (115)
  941.           Type = SHORT
  942.           N    = 1
  943.           
  944.           The number  of samples  per pixel.    SamplesPerPixel  is  1  for
  945.           bilevel, grayscale, and palette color images.  SamplesPerPixel is
  946.           3 for RGB images.
  947.           
  948.           Default = 1.  See also BitsPerSample, PhotometricInterpretation.
  949.           
  950.           
  951.           StripByteCounts
  952.           Tag  = 279  (117)
  953.           Type = SHORT or LONG
  954.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  955.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  956.           equal to 2
  957.           
  958.           For each strip, the number of bytes in that strip.  The existence
  959.           of  this   field  greatly   simplifies  the  chore  of  buffering
  960.           compressed data, if the strip size is reasonable.
  961.           
  962.           No default.  See also StripOffsets, RowsPerStrip.
  963.           
  964.           
  965.           StripOffsets
  966.           Tag  = 273  (111)
  967.           Type = SHORT or LONG
  968.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  969.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  970.           equal to 2
  971.           
  972.           For each  strip, the  byte offset  of that  strip.  The offset is
  973.           specified with  respect to  the beginning of the TIFF file.  Note
  974.           that this  implies that  each strip has a location independent of
  975.           the locations  of other  strips.   This feature may be useful for
  976.           editing applications.  This field is the only way for a reader to
  977.           find the image data, and hence must exist.
  978.           
  979.           Note that  either SHORT or LONG values can be used to specify the
  980.           strip offsets.   SHORT  values  may be used for small TIFF files.
  981.           It should  be noted,  however, that  earlier TIFF  specifications
  982.           required LONG strip offsets and that some software may not expect
  983.           SHORT values.  See Appendix G for further recommendations.
  984.           
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.           TIFF 5.0                                          page 16          TIFF 5.0                                          page 16
  995.  
  996.  
  997.           No default.  See also StripByteCounts, RowsPerStrip.
  998.           
  999.           
  1000.           XResolution
  1001.           Tag  = 282  (11A)
  1002.           Type = RATIONAL
  1003.           N    = 1
  1004.           
  1005.           The number of pixels per ResolutionUnit in the X direction, i.e.,
  1006.           in the  ImageWidth direction.   It  is, of  course, not mandatory
  1007.           that the  image be  actually printed  at the size implied by this
  1008.           parameter.   It is  up to the application to use this information
  1009.           as it wishes.
  1010.           
  1011.           No default.  See also YResolution, ResolutionUnit.
  1012.           
  1013.           
  1014.           YResolution
  1015.           Tag  = 283  (11B)
  1016.           Type = RATIONAL
  1017.           N    = 1
  1018.           
  1019.           The number of pixels per ResolutionUnit in the Y direction, i.e.,
  1020.           in the ImageLength direction.
  1021.           
  1022.           No default.  See also XResolution, ResolutionUnit.
  1023.           
  1024.           
  1025.           Informational Fields
  1026.           
  1027.           
  1028.           Informational  fields   are  fields   that  can   provide  useful
  1029.           information to  a user,  such as where the image came from.  Most
  1030.           are ASCII  fields.   An application could have some sort of _More
  1031.           Info..._ dialog box to display such information.
  1032.           
  1033.           Artist
  1034.           Tag  = 315  (13B)
  1035.           Type = ASCII
  1036.           
  1037.           Person who created the image.
  1038.           
  1039.           If you need to attach a Copyright notice to an image, this is the
  1040.           place to  do it.  In fact, you may wish to write out the contents
  1041.           of the field immediately after the 8-byte TIFF header.  Just make
  1042.           sure your  IFD and field pointers are set accordingly, and you_re
  1043.           all set.
  1044.           
  1045.           
  1046.           DateTime
  1047.           Tag  = 306  (132)
  1048.           Type = ASCII
  1049.           N    = 20
  1050.           
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.           TIFF 5.0                                          page 17          TIFF 5.0                                          page 17
  1061.  
  1062.  
  1063.           Date and  time of  image creation.   Use  the format  _YYYY:MM:DD
  1064.           HH:MM:SS_, with hours on a 24-hour clock, and one space character
  1065.           between the  date and  the time.    The  length  of  the  string,
  1066.           including the null, is 20 bytes.
  1067.           
  1068.           
  1069.           HostComputer
  1070.           Tag  = 316  (13C)
  1071.           Type = ASCII
  1072.           
  1073.           _ENIAC_, or whatever.
  1074.           
  1075.           See also Make, Model, Software.
  1076.           
  1077.           
  1078.           ImageDescription
  1079.           Tag  = 270 (10E)
  1080.           Type = ASCII
  1081.           
  1082.           For example,  a user  may wish  to attach a comment such as _1988
  1083.           company picnic_ to an image.
  1084.           
  1085.           It has  been suggested  that  this  is  what  the  newspaper  and
  1086.           magazine industry calls a _slug._
  1087.           
  1088.           
  1089.           Make
  1090.           Tag  = 271  (10F)
  1091.           Type = ASCII
  1092.           
  1093.           Manufacturer of the scanner, video digitizer, or whatever.
  1094.           
  1095.           See also Model, Software.
  1096.           
  1097.           
  1098.           Model
  1099.           Tag  = 272  (110)
  1100.           Type = ASCII
  1101.           
  1102.           The  model  name/number  of  the  scanner,  video  digitizer,  or
  1103.           whatever.
  1104.           
  1105.           This tag is intended for user information only.
  1106.           
  1107.           See also Make, Software.
  1108.           
  1109.           
  1110.           Software
  1111.           Tag  = 305  (131)
  1112.           Type = ASCII
  1113.           
  1114.           Name and  release number of the software package that created the
  1115.           image.
  1116.           
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.           TIFF 5.0                                          page 18          TIFF 5.0                                          page 18
  1127.  
  1128.  
  1129.           This tag is intended for user information only.
  1130.           
  1131.           See also Make, Model.
  1132.           
  1133.           
  1134.           Facsimile Fields
  1135.           
  1136.           
  1137.           Facsimile fields  may be  useful if  you are  using TIFF to store
  1138.           facsimile messages  in _raw_  form.  They are not recommended for
  1139.           use in interchange with desktop publishing applications.
  1140.           
  1141.           Compression (a basic tag)
  1142.           Tag  = 259  (103)
  1143.           Type = SHORT
  1144.           N    = 1
  1145.           
  1146.           3 =  Facsimile-compatible CCITT  Group 3, exactly as specified in
  1147.           _Standardization of  Group 3  facsimile  apparatus  for  document
  1148.           transmission,_   Recommendation T.4,  Volume VII, Fascicle VII.3,
  1149.           Terminal Equipment  and Protocols  for  Telematic  Services,  The
  1150.           International  Telegraph  and  Telephone  Consultative  Committee
  1151.           (CCITT), Geneva,  1985, pages  16 through  31.   Each strip  must
  1152.           begin on  a byte  boundary.   (But recall  that an image can be a
  1153.           single strip.)   Rows  that are  not the first row of a strip are
  1154.           not required  to begin on a byte boundary.  The data is stored as
  1155.           bytes,  not   words_byte-reversal  is   not  allowed.    See  the
  1156.           Group3Options field for Group 3 options such as 1D vs 2D coding.
  1157.           
  1158.           4 =  Facsimile-compatible CCITT  Group 4, exactly as specified in
  1159.           _Facsimile Coding  Schemes and Coding Control Functions for Group
  1160.           4 Facsimile Apparatus,_  Recommendation T.6, Volume VII, Fascicle
  1161.           VII.3, Terminal  Equipment and  Protocols for Telematic Services,
  1162.           The International  Telegraph and Telephone Consultative Committee
  1163.           (CCITT), Geneva,  1985, pages  40 through  48.   Each strip  must
  1164.           begin on  a byte  boundary.  Rows that are not the first row of a
  1165.           strip are  not required to begin on a byte boundary.  The data is
  1166.           stored as  bytes, not  words.   See the  Group4Options field  for
  1167.           Group 4 options.
  1168.           
  1169.           
  1170.           Group3Options
  1171.           Tag  = 292  (124)
  1172.           Type = LONG
  1173.           N    = 1
  1174.           
  1175.           See Compression=3.   This  field is  made up  of a set of 32 flag
  1176.           bits.   Unused bits are expected to be 0.  Bit 0 is the low-order
  1177.           bit.   It is probably not safe to try to read the file if any bit
  1178.           of this field is set that you don_t know the meaning of.
  1179.           
  1180.           Bit 0     is 1  for 2-dimensional  coding (else  1-dimensional is
  1181.           assumed).   For 2-D  coding, if more than one strip is specified,
  1182.           each strip  must begin  with a  1-dimensionally coded line.  That
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.           TIFF 5.0                                          page 19          TIFF 5.0                                          page 19
  1193.  
  1194.  
  1195.           is, RowsPerStrip  should be  a multiple  of  _Parameter  K_    as
  1196.           documented in the CCITT specification.
  1197.           
  1198.           Bit 1     is 1 if uncompressed mode is used.
  1199.           
  1200.           Bit 2     is 1  if fill  bits have been added as necessary before
  1201.           EOL codes  such that  EOL always  ends on  a byte  boundary, thus
  1202.           ensuring an  eol-sequence of  a 1 byte preceded by a zero nibble:
  1203.           xxxx-0000 0000-0001.
  1204.           
  1205.           Default  is   0,  for  basic  1-dimensional  coding.    See  also
  1206.           Compression.
  1207.           
  1208.           
  1209.           Group4Options
  1210.           Tag  =  293  (125)
  1211.           Type = LONG
  1212.           N    = 1
  1213.           
  1214.           See Compression=4.   This  field is  made up  of a set of 32 flag
  1215.           bits.   Unused bits are expected to be 0.  Bit 0 is the low-order
  1216.           bit.   It is probably not safe to try to read the file if any bit
  1217.           of this  field is  set that  you don_t know the meaning of.  Gray
  1218.           scale and color coding schemes are under study, and will be added
  1219.           when finalized.
  1220.           
  1221.           For 2-D  coding, each  strip is  encoded as if it were a separate
  1222.           image.   In particular, each strip begins on a byte boundary; and
  1223.           the coding  for the first row of a strip is encoded independently
  1224.           of the  previous row,  using horizontal codes, as if the previous
  1225.           row is  entirely white.   Each strip ends with the 24-bit end-of-
  1226.           facsimile block (EOFB).
  1227.           
  1228.           Bit 0     is unused.
  1229.           Bit 1     is 1 if uncompressed mode is used.
  1230.           
  1231.           Default is  0, for  basic 2-dimensional  binary compression.  See
  1232.           also Compression.
  1233.           
  1234.           
  1235.           Document Storage and Retrieval Fields
  1236.           
  1237.           
  1238.           These fields  may be  useful for  document storage  and retrieval
  1239.           applications.   They are  not recommended  for use in interchange
  1240.           with desktop publishing applications.
  1241.           
  1242.           DocumentName
  1243.           Tag  = 269  (10D)
  1244.           Type = ASCII
  1245.           
  1246.           The name of the document from which this image was scanned.
  1247.           
  1248.           See also PageName.
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.           TIFF 5.0                                          page 20          TIFF 5.0                                          page 20
  1259.  
  1260.  
  1261.           
  1262.           
  1263.           PageName
  1264.           Tag  = 285  (11D)
  1265.           Type = ASCII
  1266.           
  1267.           The name of the page from which this image was scanned.
  1268.           
  1269.           See also DocumentName.
  1270.           
  1271.           No default.
  1272.           
  1273.           PageNumber
  1274.           Tag  = 297  (129)
  1275.           Type = SHORT
  1276.           N    = 2
  1277.           
  1278.           This tag is used to specify page numbers of a multiple page (e.g.
  1279.           facsimile) document.   Two SHORT values are specified.  The first
  1280.           value is the page number; the second value is the total number of
  1281.           pages in the document.
  1282.           
  1283.           Note that  pages need  not appear  in numerical order.  The first
  1284.           page is 0 (zero).
  1285.           
  1286.           No default.
  1287.           
  1288.           
  1289.           XPosition
  1290.           Tag  = 286  (11E)
  1291.           Type = RATIONAL
  1292.           
  1293.           The X  offset of  the left side of the image, with respect to the
  1294.           left side of the page, in ResolutionUnits.
  1295.           
  1296.           No default.  See also YPosition.
  1297.           
  1298.           
  1299.           YPosition
  1300.           Tag  = 287  (11F)
  1301.           Type = RATIONAL
  1302.           
  1303.           The Y  offset of the top of the image, with respect to the top of
  1304.           the page, in ResolutionUnits.  In the TIFF coordinate scheme, the
  1305.           positive Y  direction  is  down,  so  that  YPosition  is  always
  1306.           positive.
  1307.           
  1308.           No default.  See also XPosition.
  1309.           
  1310.           
  1311.           No Longer Recommended
  1312.           
  1313.           
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.           TIFF 5.0                                          page 21          TIFF 5.0                                          page 21
  1325.  
  1326.  
  1327.           These fields  are not  recommended except  perhaps for local use.
  1328.           They should  not be used for image interchange.  They have either
  1329.           been superseded  by other fields, have been found to have serious
  1330.           drawbacks, or are simply not as useful as once thought.  They may
  1331.           be dropped entirely from a future revision of the specification.
  1332.           
  1333.           CellLength
  1334.           Tag  = 265  (109)
  1335.           Type = SHORT
  1336.           N    = 1
  1337.           
  1338.           The length, in 1-bit samples, of the dithering/halftoning matrix.
  1339.           Assumes that Threshholding = 2.
  1340.           
  1341.           This field,  plus CellWidth  and Threshholding,  are  problematic
  1342.           because they  cannot safely be used to reverse-engineer grayscale
  1343.           image data  out of dithered/halftoned black-and-white data, which
  1344.           is their  only plausible  purpose.  The only _right_ way to do it
  1345.           is to  not bother  with anything  like these  fields, and instead
  1346.           write  some  sophisticated  pattern-matching  software  that  can
  1347.           handle screen  angles that  are not  multiples of 45 degrees, and
  1348.           other such challenging dithered/halftoned data.
  1349.           
  1350.           So we  do not  recommend trying  to convert dithered or halftoned
  1351.           data into  grayscale data.   Dithered  and halftoned data require
  1352.           careful treatment  to avoid  _stretch marks,_ but it can be done.
  1353.           If you  want grayscale images, get them directly from the scanner
  1354.           or frame grabber or whatever.
  1355.           
  1356.           No default.  See also Threshholding.
  1357.           
  1358.           
  1359.           CellWidth
  1360.           Tag  = 264  (108)
  1361.           Type = SHORT
  1362.           N    = 1
  1363.           
  1364.           The width, in 1-bit samples, of the dithering/halftoning matrix.
  1365.           
  1366.           No default.   See  also Threshholding.    See  the  comments  for
  1367.           CellLength.
  1368.           
  1369.           
  1370.           FillOrder
  1371.           Tag  = 266  (10A)
  1372.           Type = SHORT
  1373.           N    = 1
  1374.           
  1375.           The order of data values within a byte.
  1376.           1 = most significant bits of the byte are filled first.  That is,
  1377.           data values  (or code  words) are  ordered from high order bit to
  1378.           low order bit within a byte.
  1379.           2 =  least significant  bits are  filled  first.    Since  little
  1380.           interest has  been expressed  in least-significant  fill order to
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.           TIFF 5.0                                          page 22          TIFF 5.0                                          page 22
  1391.  
  1392.  
  1393.           date, and since it is easy and inexpensive for writers to reverse
  1394.           bit order (use a 256-byte lookup table), we recommend FillOrder=2
  1395.           for private (non-interchange) use only.
  1396.           
  1397.           Default is FillOrder = 1.
  1398.           
  1399.           
  1400.           FreeByteCounts
  1401.           Tag  = 289  (121)
  1402.           Type = LONG
  1403.           
  1404.           For each  _free block_   in  the file, the number of bytes in the
  1405.           block.
  1406.           
  1407.           TIFF  readers   can  ignore  FreeOffsets  and  FreeByteCounts  if
  1408.           present.
  1409.           
  1410.           FreeOffsets and  FreeByteCounts do  not constitute a remapping of
  1411.           the logical address space of the file.
  1412.           
  1413.           Since this  information can  be generated  by scanning  the IFDs,
  1414.           StripOffsets, and StripByteCounts, FreeByteCounts and FreeOffsets
  1415.           are not needed.
  1416.           
  1417.           In addition, it is not clear what should happen if FreeByteCounts
  1418.           and FreeOffsets exist in more than one IFD.
  1419.           
  1420.           See also FreeOffsets.
  1421.           
  1422.           
  1423.           FreeOffsets
  1424.           Tag  = 288  (120)
  1425.           Type = LONG
  1426.           
  1427.           For each _free block_  in the file, its byte offset.
  1428.           
  1429.           See also FreeByteCounts.
  1430.           
  1431.           
  1432.           MaxSampleValue
  1433.           Tag  = 281  (119)
  1434.           Type = SHORT
  1435.           N    = SamplesPerPixel
  1436.           
  1437.           The maximum  used sample  value.    For  example,  if  the  image
  1438.           consists of  6-bit data  low-order-justified  into  8-bit  bytes,
  1439.           MaxSampleValue will  be no  greater than 63. This is field is not
  1440.           to be  used to  affect the  visual appearance  of the  image when
  1441.           displayed.   Nor should  the values  of  this  field  affect  the
  1442.           interpretation of  any other  field.    Use  it  for  statistical
  1443.           purposes only.
  1444.           
  1445.           Default is 2**(BitsPerSample) - 1.
  1446.           
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.           TIFF 5.0                                          page 23          TIFF 5.0                                          page 23
  1457.  
  1458.  
  1459.           
  1460.           MinSampleValue
  1461.           Tag  = 280  (118)
  1462.           Type = SHORT
  1463.           N    = SamplesPerPixel
  1464.           
  1465.           The minimum  used sample  value.  This field is not to be used to
  1466.           affect the  visual appearance  of the  image when displayed.  See
  1467.           the comments for MaxSampleValue.
  1468.           
  1469.           Default is 0.
  1470.           
  1471.           
  1472.           SubfileType
  1473.           Tag  = 255  (FF)
  1474.           Type = SHORT
  1475.           N    = 1
  1476.           
  1477.           A general  indication of  the kind  of data  that is contained in
  1478.           this subfile.  Currently defined values are:
  1479.           
  1480.           1 =  full  resolution  image  data_ImageWidth,  ImageLength,  and
  1481.           StripOffsets are required fields; and
  1482.           2 =  reduced resolution  image data_ImageWidth,  ImageLength, and
  1483.           StripOffsets are  required fields.   It is further assumed that a
  1484.           reduced resolution  image is  a reduced  version  of  the  entire
  1485.           extent of the corresponding full resolution data.
  1486.           3 =  single page  of a  multi-page image  (see the PageNumber tag
  1487.           description).
  1488.           
  1489.           Note that several image types can be found in a single TIFF file,
  1490.           with each subfile described by its own IFD.
  1491.           
  1492.           No default.
  1493.           
  1494.           Continued use  of this  field is not recommended.  Writers should
  1495.           instead use the new and more general NewSubfileType field.
  1496.           
  1497.           
  1498.           Orientation
  1499.           Tag  = 274 (112)
  1500.           Type = SHORT
  1501.           N    = 1
  1502.           
  1503.           1 =  The 0th  row represents the visual top of the image, and the
  1504.           0th column represents the visual left hand side.
  1505.           2 =  The 0th  row represents the visual top of the image, and the
  1506.           0th column represents the visual right hand side.
  1507.           3 =  The 0th  row represents  the visual bottom of the image, and
  1508.           the 0th column represents the visual right hand side.
  1509.           4 =  The 0th  row represents  the visual bottom of the image, and
  1510.           the 0th column represents the visual left hand side.
  1511.           5 =  The 0th  row represents  the visual  left hand  side of  the
  1512.           image, and the 0th column represents the visual top.
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.           TIFF 5.0                                          page 24          TIFF 5.0                                          page 24
  1523.  
  1524.  
  1525.           6 =  The 0th  row represents  the visual  right hand  side of the
  1526.           image, and the 0th column represents the visual top.
  1527.           7 =  The 0th  row represents  the visual  right hand  side of the
  1528.           image, and the 0th column represents the visual bottom.
  1529.           8 =  The 0th  row represents  the visual  left hand  side of  the
  1530.           image, and the 0th column represents the visual bottom.
  1531.           
  1532.           Default is 1.
  1533.           
  1534.           This field is recommended for private (non-interchange) use only.
  1535.           It is extremely costly for most readers to perform image rotation
  1536.           _on the  fly,_ i.e.,  when importing  and printing;  and users of
  1537.           most  desktop  publishing  applications  do  not  expect  a  file
  1538.           imported by the application to be altered permanently in any way.
  1539.           
  1540.           
  1541.           Threshholding
  1542.           Tag  = 263  (107)
  1543.           Type = SHORT
  1544.           N    = 1
  1545.           
  1546.           1 = a bilevel _line art_  scan.  BitsPerSample must be 1.
  1547.           2 =  a _dithered_   scan, usually of continuous tone data such as
  1548.           photographs. BitsPerSample must be 1.
  1549.           3 = Error Diffused.
  1550.           
  1551.           Default is Threshholding = 1.  See also CellWidth, CellLength.
  1552.           4) Private Fields
  1553.           
  1554.           An organization  may wish to store information that is meaningful
  1555.           to only that organization in a TIFF file.  Tags numbered 32768 or
  1556.           higher  are  reserved  for  that  purpose.    Upon  request,  the
  1557.           administrator will  allocate and register a block of private tags
  1558.           for an  organization, to  avoid  possible  conflicts  with  other
  1559.           organizations.   Tags are  normally allocated  in blocks of five.
  1560.           If that is not enough, feel free to ask for more. You do not need
  1561.           to tell  the TIFF administrator or anyone else what you are going
  1562.           to use them for.
  1563.           
  1564.           Private enumerated  values  can  be  accommodated  in  a  similar
  1565.           fashion.   For example,  you may  wish to  experiment with  a new
  1566.           compression scheme  within TIFF.   Enumeration constants numbered
  1567.           32768 or  higher are  reserved for  private usage.  Upon request,
  1568.           the  administrator   will  allocate   and  register  a  block  of
  1569.           enumerated values  for a  particular field  (Compression, in  our
  1570.           example), to avoid possible conflicts.
  1571.           
  1572.           Tags and  values which  are allocated in the private number range
  1573.           are not  prohibited from  being included  in a future revision of
  1574.           this specification.   Several  such instances can be found in the
  1575.           TIFF specification.
  1576.           
  1577.           Do not  choose your  own tag  numbers.  If you do, it could cause
  1578.           serious problems some day.
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.           TIFF 5.0                                          page 25          TIFF 5.0                                          page 25
  1589.  
  1590.  
  1591.           
  1592.           
  1593.           5) Image File Format Issues
  1594.           
  1595.           In the  quest to  give users no reason NOT to buy a product, some
  1596.           scanning and  image editing  applications overwhelm users with an
  1597.           incredible number  of _Save  As..._ options.  Let_s get rid of as
  1598.           many of  these as  we possibly  can.   For example, a single TIFF
  1599.           choice should  suffice once most major readers are supporting the
  1600.           three TIFF compression schemes; then writers can always compress.
  1601.           And given  TIFF_s flexibility,  including private  tag and  image
  1602.           editing  support   features,  there  does  not  seem  to  be  any
  1603.           legitimate reason  for continuing  to  write  image  files  using
  1604.           proprietary formats.
  1605.           
  1606.           Along the  same lines,  there is no excuse for making a user have
  1607.           to know  the file  format of  a file  that is  to be  read by  an
  1608.           application program.   TIFF  files, as  well as  most other  file
  1609.           formats, contain  sufficient information  to enable  software  to
  1610.           automatically and  reliably distinguish  one type  of  file  from
  1611.           another.
  1612.           
  1613.           
  1614.           6) For Further Information
  1615.           
  1616.           Contact the  Aldus Developers_ Desk for sample TIFF files, source
  1617.           code fragments,  and  a  list  of  features  that  are  currently
  1618.           supported in  Aldus products.   The Aldus Developers_ Desk is the
  1619.           current _TIFF administrator._
  1620.           
  1621.           Various TIFF  related  aids  are  found  in  Microsoft_s  Windows
  1622.           Developers Tookit for developers writing Windows applications.
  1623.           
  1624.           Finally, a  number of  scanner vendors are providing various TIFF
  1625.           services, such  as helping  to distribute  the TIFF specification
  1626.           and answering  TIFF questions.   Contact  the appropriate product
  1627.           manager or developer support service group.
  1628.           
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.           TIFF 5.0                                          page 26          TIFF 5.0                                          page 26
  1655.  
  1656.  
  1657.           Appendix A:  Tag Structure Rationale
  1658.           
  1659.           
  1660.           A file  format is  defined by  both form (structure) and content.
  1661.           The content of TIFF consists of definitions of individual fields.
  1662.           It is therefore the content that we are ultimately interested in.
  1663.           The structure  merely tells  us how  to find the fields.  Yet the
  1664.           structure deserves  serious consideration for a number of reasons
  1665.           that are not at all obvious at first glance.  Since the structure
  1666.           described  herein   departs  significantly   from  several  other
  1667.           approaches, it may be useful to discuss the rationale behind it.
  1668.           
  1669.           The simplest,  most straightforward  structure for something like
  1670.           an image  file is  a positional  format.  In a positional scheme,
  1671.           the location  of the  data defines  what the  data  means.    For
  1672.           example, the  field for  _number of  rows_ might  begin  at  byte
  1673.           offset 30 in the image file.
  1674.           
  1675.           This approach  is simple and easy to implement and is perfect for
  1676.           static environments.   But  if a  significant amount  of  ongoing
  1677.           change must  be accommodated,  subtle problems  begin to  appear.
  1678.           For example,  suppose that  a field  must be superseded by a new,
  1679.           more general  field.  You could bump a version number to flag the
  1680.           change.   Then  new  software  has  no  problem  doing  something
  1681.           sensible with  old data, and all old software will reject the new
  1682.           data, even  software that  didn_t care about the old field.  This
  1683.           may seem like no more than a minor annoyance at first glance, but
  1684.           causing old  software to  break more  often than  it would really
  1685.           need to  can be very costly and, inevitably, causes much gnashing
  1686.           of teeth among customers.
  1687.           
  1688.           Furthermore, it  can be  avoided.   One approach  is to  store  a
  1689.           _valid_ flag  bit for each field.  Now you don_t have to bump the
  1690.           version number,  as long  as you  can put the new field somewhere
  1691.           that doesn_t  disturb any  of the  old fields.  Old software that
  1692.           didn_t care about that old field anyway can continue to function.
  1693.           (Old software  that did  care will of course have to give up, but
  1694.           this is an unavoidable price to be paid for the sake of progress,
  1695.           barring total omniscience.)
  1696.           
  1697.           Another problem  that crops  up frequently is that certain fields
  1698.           are likely  to make  sense only  if  other  fields  have  certain
  1699.           values.   This is not such a serious problem in practice; it just
  1700.           makes things  more confusing.   Nevertheless,  we note  that  the
  1701.           _valid_ flag bits described in the previous paragraph can help to
  1702.           clarify the situation.
  1703.           
  1704.           Field-dumping  programs   can  be  very  helpful  for  diagnostic
  1705.           purposes.   A desirable  characteristic of such a program is that
  1706.           it doesn_t  have to  know much  about what  it is  dumping.    In
  1707.           particular, it would be nice if the program could dump ASCII data
  1708.           in ASCII  format, integer  data in  integer format,  and  so  on,
  1709.           without having  to teach  the program  about new  fields all  the
  1710.           time.   So maybe  we should  add a  _data type_  component to our
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.           TIFF 5.0                                          page 27          TIFF 5.0                                          page 27
  1721.  
  1722.  
  1723.           fields, plus  information on  how long  the field is, so that our
  1724.           dump program can walk through the fields without knowing what the
  1725.           fields _mean."
  1726.           
  1727.           But note  that if we add one more component to each field, namely
  1728.           a tag  that tells  what the field means, we can dispense with the
  1729.           _valid_ flag  bits, and  we can  also avoid  wasting space on the
  1730.           non-valid fields in the file.  Simple image creation applications
  1731.           can write out several fields and be done.
  1732.           
  1733.           We have  now derived  the essentials  of a  tag-based image  file
  1734.           format.
  1735.           
  1736.           Finally, a  caveat.  A tag based scheme cannot guarantee painless
  1737.           growth.   But is  does provide  a useful  tool to  assist in  the
  1738.           process.
  1739.           
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.           TIFF 5.0                                          page 28          TIFF 5.0                                          page 28
  1787.  
  1788.  
  1789.           Appendix B:  Data Compression_Scheme 2
  1790.           
  1791.           
  1792.           Abstract
  1793.           
  1794.           This document  describes a  method for  compressing bilevel  data
  1795.           that is  based on  the CCITT  Group 3  1D  facsimile  compression
  1796.           scheme.
  1797.           
  1798.           
  1799.           References
  1800.           
  1801.           1.   _Standardization of Group 3 facsimile apparatus for document
  1802.           transmission,_ Recommendation  T.4, Volume  VII, Fascicle  VII.3,
  1803.           Terminal Equipment  and Protocols  for  Telematic  Services,  The
  1804.           International  Telegraph  and  Telephone  Consultative  Committee
  1805.           (CCITT), Geneva, 1985, pages 16 through 31.
  1806.           2.   _Facsimile Coding  Schemes and  Coding Control Functions for
  1807.           Group 4  Facsimile Apparatus,_  Recommendation T.6,  Volume  VII,
  1808.           Fascicle VII.3,  Terminal Equipment  and Protocols  for Telematic
  1809.           Services, The  International Telegraph and Telephone Consultative
  1810.           Committee (CCITT), Geneva, 1985, pages 40 through 48.
  1811.           
  1812.           We do  not believe that these documents are necessary in order to
  1813.           implement Compression=2.   We  have included  (verbatim  in  most
  1814.           places) all the pertinent information in this Appendix.  However,
  1815.           if you  wish to  order the  documents, you  can  write  to  ANSI,
  1816.           Attention: Sales,  1430 Broadway, New York, N.Y., 10018.  Ask for
  1817.           the publication  listed above_it contains both Recommendation T.4
  1818.           and T.6.
  1819.           
  1820.           
  1821.           Relationship to the CCITT Specifications
  1822.           
  1823.           The  CCITT   Group  3   and  Group   4  specifications   describe
  1824.           communications protocols for a particular class of devices.  They
  1825.           are not  by themselves sufficient to describe a disk data format.
  1826.           Fortunately, however,  the CCITT  coding schemes  can be  readily
  1827.           adapted to this different environment.  The following is one such
  1828.           adaptation.   Most of  the language  is copied  directly from the
  1829.           CCITT specifications.
  1830.           
  1831.           
  1832.           Coding Scheme
  1833.           
  1834.           A line  (row) of  data is composed of a series of variable length
  1835.           code words.  Each code word represents a run length of either all
  1836.           white or  all black.   (Actually,  more than one code word may be
  1837.           required to  code a  given run,  in a  manner  described  below.)
  1838.           White runs and black runs alternate.
  1839.           
  1840.           In order  to ensure  that the  receiver (decompressor)  maintains
  1841.           color synchronization, all data lines will begin with a white run
  1842.           length code  word set.   If  the actual  scan line  begins with a
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.           TIFF 5.0                                          page 29          TIFF 5.0                                          page 29
  1853.  
  1854.  
  1855.           black run,  a white  run length  of zero  will be sent (written).
  1856.           Black or  white run  lengths are  defined by  the code  words  in
  1857.           Tables 1  and 2.   The  code words are of two types:  Terminating
  1858.           code  words   and  Make-up  code  words.    Each  run  length  is
  1859.           represented by  zero or  more  Make-up  code  words  followed  by
  1860.           exactly one Terminating code word.
  1861.           
  1862.           Run lengths  in the  range of  0 to  63 pels (pixels) are encoded
  1863.           with their appropriate Terminating code word.  Note that there is
  1864.           a different list of code words for black and white run lengths.
  1865.           
  1866.           Run lengths in the range of 64 to 2623 (2560+63) pels are encoded
  1867.           first by  the Make-up  code word representing the run length that
  1868.           is nearest  to, not  longer than,  that required.   This  is then
  1869.           followed by the Terminating code word representing the difference
  1870.           between the required run length and the run length represented by
  1871.           the Make-up code.
  1872.           
  1873.           Run lengths  in the range of lengths longer than or equal to 2624
  1874.           pels are  coded first  by the  Make-up code  of  2560.    If  the
  1875.           remaining part  of the run (after the first Make-up code of 2560)
  1876.           is 2560  pels or  greater, additional Make-up code(s) of 2560 are
  1877.           issued until the remaining part of the run becomes less than 2560
  1878.           pels.   Then  the  remaining  part  of  the  run  is  encoded  by
  1879.           Terminating code  or  by  Make-up  code  plus  Terminating  code,
  1880.           according to the range mentioned above.
  1881.           
  1882.           It is  considered an  unrecoverable error  if the  sum of the run
  1883.           lengths for  a line  does not  equal the  value of the ImageWidth
  1884.           field.
  1885.           
  1886.           New rows always begin on the next available byte boundary.
  1887.           
  1888.           No EOL  code words  are used.   No fill bits are used, except for
  1889.           the ignored  bits at  the end  of the last byte of a row.  RTC is
  1890.           not used.
  1891.           
  1892.           
  1893.           Table 1/T.4  Terminating codes
  1894.           
  1895.           
  1896.           White          Black
  1897.            run Code  run Code
  1898.           length    word length    word
  1899.            ----     ---- ------    ----
  1900.           
  1901.            0   00110101   0   0000110111
  1902.            1   000111     1   010
  1903.            2   0111  2   11
  1904.            3   1000  3   10
  1905.            4   1011  4   011
  1906.            5   1100  5   0011
  1907.            6   1110  6   0010
  1908.            7   1111  7   00011
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.           TIFF 5.0                                          page 30          TIFF 5.0                                          page 30
  1919.  
  1920.  
  1921.            8   10011      8   000101
  1922.            9   10100      9   000100
  1923.           10   00111     10   0000100
  1924.           11   01000     11   0000101
  1925.           12   001000    12   0000111
  1926.           13   000011    13   00000100
  1927.           14   110100    14   00000111
  1928.           15   110101    15   000011000
  1929.           16   101010    16   0000010111
  1930.           17   101011    17   0000011000
  1931.           18   0100111   18   0000001000
  1932.           19   0001100   19   00001100111
  1933.           20   0001000   20   00001101000
  1934.           21   0010111   21   00001101100
  1935.           22   0000011   22   00000110111
  1936.           23   0000100   23   00000101000
  1937.           24   0101000   24   00000010111
  1938.           25   0101011   25   00000011000
  1939.           26   0010011   26   000011001010
  1940.           27   0100100   27   000011001011
  1941.           28   0011000   28   000011001100
  1942.           29   00000010  29   000011001101
  1943.           30   00000011  30   000001101000
  1944.           31   00011010  31   000001101001
  1945.           32   00011011  32   000001101010
  1946.           33   00010010  33   000001101011
  1947.           34   00010011  34   000011010010
  1948.           35   00010100  35   000011010011
  1949.           36   00010101  36   000011010100
  1950.           37   00010110  37   000011010101
  1951.           38   00010111  38   000011010110
  1952.           39   00101000  39   000011010111
  1953.           40   00101001  40   000001101100
  1954.           41   00101010  41   000001101101
  1955.           42   00101011  42   000011011010
  1956.           43   00101100  43   000011011011
  1957.           44   00101101  44   000001010100
  1958.           45   00000100  45   000001010101
  1959.           46   00000101  46   000001010110
  1960.           47   00001010  47   000001010111
  1961.           48   00001011  48   000001100100
  1962.           49   01010010  49   000001100101
  1963.           50   01010011  50   000001010010
  1964.           51   01010100  51   000001010011
  1965.           52   01010101  52   000000100100
  1966.           53   00100100  53   000000110111
  1967.           54   00100101  54   000000111000
  1968.           55   01011000  55   000000100111
  1969.           56   01011001  56   000000101000
  1970.           57   01011010  57   000001011000
  1971.           58   01011011  58   000001011001
  1972.           59   01001010  59   000000101011
  1973.           60   01001011  60   000000101100
  1974.           61   00110010  61   000001011010
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.           TIFF 5.0                                          page 31          TIFF 5.0                                          page 31
  1985.  
  1986.  
  1987.           62   00110011  62   000001100110
  1988.           63   00110100  63   000001100111   
  1989.           
  1990.           
  1991.           
  1992.           
  1993.           Table 2/T.4  Make-up codes
  1994.           
  1995.           White          Black
  1996.            run Code  run Code
  1997.           length    word      length    word
  1998.           ------    ---- ------    ----
  1999.           
  2000.             64 11011       64 0000001111
  2001.            128 10010      128 000011001000
  2002.            192 010111     192 000011001001
  2003.            256 0110111    256 000001011011
  2004.            320 00110110   320 000000110011
  2005.            384 00110111   384 000000110100
  2006.            448 01100100   448 000000110101
  2007.            512 01100101   512 0000001101100
  2008.            576 01101000   576 0000001101101
  2009.            640 01100111   640 0000001001010
  2010.            704 011001100  704 0000001001011
  2011.            768 011001101  768 0000001001100
  2012.            832 011010010  832 0000001001101
  2013.            896 011010011  896 0000001110010
  2014.            960 011010100  960 0000001110011
  2015.           1024 011010101 1024 0000001110100
  2016.           1088 011010110 1088 0000001110101
  2017.           1152 011010111 1152 0000001110110
  2018.           1216 011011000 1216 0000001110111
  2019.           1280 011011001 1280 0000001010010
  2020.           1344 011011010 1344 0000001010011
  2021.           1408 011011011 1408 0000001010100
  2022.           1472 010011000 1472 0000001010101
  2023.           1536 010011001 1536 0000001011010
  2024.           1600 010011010 1600 0000001011011
  2025.           1664 011000    1664 0000001100100
  2026.           1728 010011011 1728 0000001100101
  2027.            EOL 000000000001    EOL 000000000001
  2028.           
  2029.           
  2030.           
  2031.           
  2032.           Additional make-up codes
  2033.           
  2034.           White
  2035.           and
  2036.           Black     Make-up
  2037.           run  code
  2038.           length    word
  2039.           ------    ----
  2040.           
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.           TIFF 5.0                                          page 32          TIFF 5.0                                          page 32
  2051.  
  2052.  
  2053.           1792 00000001000
  2054.           1856 00000001100
  2055.           1920 00000001101
  2056.           1984 000000010010
  2057.           2048 000000010011
  2058.           2112 000000010100
  2059.           2176 000000010101
  2060.           2240 000000010110
  2061.           2304 000000010111
  2062.           2368 000000011100
  2063.           2432 000000011101
  2064.           2496 000000011110
  2065.           2560 000000011111
  2066.           
  2067.           
  2068.           
  2069.           
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.           TIFF 5.0                                          page 33          TIFF 5.0                                          page 33
  2117.  
  2118.  
  2119.           Appendix C: Data Compression_Scheme 32773_
  2120.           _PackBits_
  2121.           
  2122.           
  2123.           Abstract
  2124.           
  2125.           This document  describes a  simple compression scheme for bilevel
  2126.           scanned and paint type files.
  2127.           
  2128.           
  2129.           Motivation
  2130.           
  2131.           The TIFF  specification defines  a number of compression schemes.
  2132.           Compression type  1 is  really no  compression, other  than basic
  2133.           pixel  packing.     Compression   type  2,   based  on  CCITT  1D
  2134.           compression,  is   powerful,  but   not  trivial   to  implement.
  2135.           Compression type  5 is  typically very effective for most bilevel
  2136.           images, as  well as  many deeper images such as palette color and
  2137.           grayscale images, but is also not trivial to implement.  PackBits
  2138.           is a simple but often effective alternative.
  2139.           
  2140.           
  2141.           Description
  2142.           
  2143.           Several good schemes were already in use in various settings.  We
  2144.           somewhat arbitrarily picked the Macintosh PackBits scheme.  It is
  2145.           byte oriented,  so there  is no problem with word alignment.  And
  2146.           it has a good worst case behavior (at most 1 extra byte for every
  2147.           128 input  bytes).    For  Macintosh  users,  there  are  toolbox
  2148.           utilities PackBits  and UnPackBits that will do the work for you,
  2149.           but it is easy to implement your own routines.
  2150.           
  2151.           A pseudo code fragment to unpack might look like this:
  2152.           
  2153.           Loop  until  you  get  the  number  of  unpacked  bytes  you  are
  2154.           expecting:
  2155.                Read the next source byte into n.
  2156.                If n is between 0 and 127 inclusive, copy the next n+1 bytes
  2157.           literally.
  2158.                Else if  n is  between -127  and -1 inclusive, copy the next
  2159.           byte -n+1 times.
  2160.                Else if n is 128, noop.
  2161.           Endloop
  2162.           
  2163.           In the  inverse routine,  it_s best to encode a 2-byte repeat run
  2164.           as a replicate run except when preceded and followed by a literal
  2165.           run, in  which case it_s best to merge the three into one literal
  2166.           run.  Always encode 3-byte repeats as replicate runs.
  2167.           
  2168.           So that_s the algorithm.  Here are some other rules:
  2169.           
  2170.           ╤    Each row  must be packed separately.  Do not compress across
  2171.           row boundaries.
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.           TIFF 5.0                                          page 34          TIFF 5.0                                          page 34
  2183.  
  2184.  
  2185.           ╤    The number  of uncompressed  bytes per  row is defined to be
  2186.           (ImageWidth +  7) / 8.  If the uncompressed bitmap is required to
  2187.           have an  even number  of bytes  per row,  decompress  into  word-
  2188.           aligned buffers.
  2189.           ╤    If a  run is  larger  than  128  bytes,  simply  encode  the
  2190.           remainder of the run as one or more additional replicate runs.
  2191.           
  2192.           When  PackBits   data  is  uncompressed,  the  result  should  be
  2193.           interpreted as per compression type 1 (no compression).
  2194.           
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.           TIFF 5.0                                          page 35          TIFF 5.0                                          page 35
  2249.  
  2250.  
  2251.           Appendix D
  2252.           
  2253.           
  2254.           Appendix D  has been  deleted.   It formerly contained guidelines
  2255.           for passing  TIFF files on the Microsoft Windows Clipboard.  This
  2256.           was judged to not be a good idea, in light of the ever-increasing
  2257.           size of  scanned images.   Applications are instead encouraged to
  2258.           employ file-based  mechanisms to  exchange  TIFF  data.    Aldus_
  2259.           PageMaker, for  example, implements  a _File  Place_  command  to
  2260.           allow TIFF files to be imported.
  2261.           
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.           TIFF 5.0                                          page 36          TIFF 5.0                                          page 36
  2315.  
  2316.  
  2317.           Appendix E:  Numerical List of TIFF Tags
  2318.           
  2319.           
  2320.           NewSubfileType
  2321.           Tag  =  254  (FE)
  2322.           Type = LONG
  2323.           N    = 1
  2324.           
  2325.           SubfileType
  2326.           Tag  = 255  (FF)
  2327.           Type = SHORT
  2328.           N    = 1
  2329.           
  2330.           ImageWidth
  2331.           Tag  = 256  (100)
  2332.           Type = SHORT or LONG
  2333.           N    = 1
  2334.           
  2335.           ImageLength
  2336.           Tag  = 257  (101)
  2337.           Type = SHORT or LONG
  2338.           N    = 1
  2339.           
  2340.           BitsPerSample
  2341.           Tag  = 258  (102)
  2342.           Type = SHORT
  2343.           N    = SamplesPerPixel
  2344.           
  2345.           Compression
  2346.           Tag  = 259  (103)
  2347.           Type = SHORT
  2348.           N    = 1
  2349.           
  2350.           PhotometricInterpretation
  2351.           Tag  = 262  (106)
  2352.           Type = SHORT
  2353.           N    = 1
  2354.           
  2355.           
  2356.           Threshholding
  2357.           Tag  = 263  (107)
  2358.           Type = SHORT
  2359.           N    = 1
  2360.           
  2361.           CellWidth
  2362.           Tag  = 264  (108)
  2363.           Type = SHORT
  2364.           N    = 1
  2365.           
  2366.           CellLength
  2367.           Tag  = 265  (109)
  2368.           Type = SHORT
  2369.           N    = 1
  2370.           
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.           TIFF 5.0                                          page 37          TIFF 5.0                                          page 37
  2381.  
  2382.  
  2383.           FillOrder
  2384.           Tag  = 266  (10A)
  2385.           Type = SHORT
  2386.           N    = 1
  2387.           
  2388.           DocumentName
  2389.           Tag  = 269  (10D)
  2390.           Type = ASCII
  2391.           
  2392.           ImageDescription
  2393.           Tag  = 270 (10E)
  2394.           Type = ASCII
  2395.           
  2396.           Make
  2397.           Tag  = 271  (10F)
  2398.           Type = ASCII
  2399.           
  2400.           Model
  2401.           Tag  = 272  (110)
  2402.           Type = ASCII
  2403.           
  2404.           StripOffsets
  2405.           Tag  = 273  (111)
  2406.           Type = SHORT or LONG
  2407.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  2408.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  2409.           equal to 2
  2410.           
  2411.           Orientation
  2412.           Tag  = 274 (112)
  2413.           Type = SHORT
  2414.           N    = 1
  2415.           
  2416.           SamplesPerPixel
  2417.           Tag  = 277  (115)
  2418.           Type = SHORT
  2419.           N    = 1
  2420.           
  2421.           RowsPerStrip
  2422.           Tag  = 278  (116)
  2423.           Type = SHORT or LONG
  2424.           N    = 1
  2425.           
  2426.           StripByteCounts
  2427.           Tag  = 279  (117)
  2428.           Type = LONG or SHORT
  2429.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  2430.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  2431.           equal to 2.
  2432.           
  2433.           MinSampleValue
  2434.           Tag  = 280  (118)
  2435.           Type = SHORT
  2436.           N    = SamplesPerPixel
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.           TIFF 5.0                                          page 38          TIFF 5.0                                          page 38
  2447.  
  2448.  
  2449.           
  2450.           MaxSampleValue
  2451.           Tag  = 281  (119)
  2452.           Type = SHORT
  2453.           N    = SamplesPerPixel
  2454.           
  2455.           XResolution
  2456.           Tag  = 282  (11A)
  2457.           Type = RATIONAL
  2458.           N    = 1
  2459.           
  2460.           YResolution
  2461.           Tag  = 283  (11B)
  2462.           Type = RATIONAL
  2463.           N    = 1
  2464.           
  2465.           PlanarConfiguration
  2466.           Tag  = 284  (11C)
  2467.           Type = SHORT
  2468.           N    = 1
  2469.           
  2470.           PageName
  2471.           Tag  = 285  (11D)
  2472.           Type = ASCII
  2473.           
  2474.           
  2475.           XPosition
  2476.           Tag  = 286  (11E)
  2477.           Type = RATIONAL
  2478.           
  2479.           YPosition
  2480.           Tag  = 287  (11F)
  2481.           Type = RATIONAL
  2482.           
  2483.           FreeOffsets
  2484.           Tag  = 288  (120)
  2485.           Type = LONG
  2486.           
  2487.           FreeByteCounts
  2488.           Tag  = 289  (121)
  2489.           Type = LONG
  2490.           
  2491.           GrayResponseUnit
  2492.           Tag  = 290 (122)
  2493.           Type = SHORT
  2494.           N    = 1
  2495.           
  2496.           GrayResponseCurve
  2497.           Tag  = 291 (123)
  2498.           Type = SHORT
  2499.           N    = 2**BitsPerSample
  2500.           
  2501.           Group3Options
  2502.           Tag  = 292  (124)
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.           TIFF 5.0                                          page 39          TIFF 5.0                                          page 39
  2513.  
  2514.  
  2515.           Type = LONG
  2516.           N    = 1
  2517.           
  2518.           Group4Options
  2519.           Tag  =  293  (125)
  2520.           Type = LONG
  2521.           N    = 1
  2522.           
  2523.           ResolutionUnit
  2524.           Tag  = 296 (128)
  2525.           Type = SHORT
  2526.           N    = 1
  2527.           
  2528.           PageNumber
  2529.           Tag  = 297  (129)
  2530.           Type = SHORT
  2531.           N    = 2
  2532.           
  2533.           ColorResponseCurves
  2534.           Tag  = 301 (12D)
  2535.           Type = SHORT
  2536.           N    = 3 * (2**BitsPerSample)
  2537.           
  2538.           Software
  2539.           Tag  = 305  (131)
  2540.           Type = ASCII
  2541.           
  2542.           DateTime
  2543.           Tag  = 306  (132)
  2544.           Type = ASCII
  2545.           N    = 20
  2546.           
  2547.           Artist
  2548.           Tag  = 315  (13B)
  2549.           Type = ASCII
  2550.           
  2551.           HostComputer
  2552.           Tag  = 316  (13C)
  2553.           Type = ASCII
  2554.           
  2555.           Predictor
  2556.           Tag  = 317 (13D)
  2557.           Type = SHORT
  2558.           N    = 1
  2559.           
  2560.           WhitePoint
  2561.           Tag  = 318 (13E)
  2562.           Type = RATIONAL
  2563.           N    = 2
  2564.           
  2565.           PrimaryChromaticities
  2566.           Tag  = 319 (13F)
  2567.           Type = RATIONAL
  2568.           N    = 6
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.           TIFF 5.0                                          page 40          TIFF 5.0                                          page 40
  2579.  
  2580.  
  2581.           
  2582.           ColorMap
  2583.           Tag  = 320 (140)
  2584.           Type = SHORT
  2585.           N    = 3 * (2**BitsPerSample)
  2586.           
  2587.  
  2588.  
  2589.  
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.           TIFF 5.0                                          page 41          TIFF 5.0                                          page 41
  2645.  
  2646.  
  2647.           Appendix F:  Data Compression_Scheme 5_LZW
  2648.           Compression
  2649.           
  2650.           
  2651.           Abstract
  2652.           
  2653.           This document describes an adaptive compression scheme for raster
  2654.           images.
  2655.           
  2656.           
  2657.           Reference
  2658.           
  2659.           Terry  A.   Welch,  _A   Technique  for   High  Performance  Data
  2660.           Compression_,  IEEE   Computer,  vol.   17  no.  6  (June  1984).
  2661.           Describes the  basic Lempel-Ziv  & Welch  (LZW) algorithm.    The
  2662.           author_s goal  in the  article is  to describe  a  hardware-based
  2663.           compressor that could be built into a disk controller or database
  2664.           engine, and  used on  all types  of data.   There  is no specific
  2665.           discussion of  raster images.    We  intend  to  give  sufficient
  2666.           information in  this Appendix so that the article is not required
  2667.           reading.
  2668.           
  2669.           
  2670.           Requirements
  2671.           
  2672.           A compression  scheme with  the following  characteristics should
  2673.           work well in a desktop publishing environment:
  2674.           
  2675.           ╤    Must work well for images of any bit depth, including images
  2676.           deeper than 8 bits per sample.
  2677.           ╤    Must be effective:  an average compression ratio of at least
  2678.           2:1 or  better.    And  it  must  have  a  reasonable  worst-case
  2679.           behavior, in case something really strange is thrown at it.
  2680.           ╤    Should  not  depend  on  small  variations  between  pixels.
  2681.           Palette color  images tend  to contain  abrupt changes  in  index
  2682.           values, due to common patterning and dithering techniques.  These
  2683.           abrupt changes  do tend to be repetitive, however, and the scheme
  2684.           should make use of this fact.
  2685.           ╤    For images  generated by  paint programs,  the scheme should
  2686.           not depend on a particular pattern width.  8x8 pixel patterns are
  2687.           common now, but we should not assume that this situation will not
  2688.           change.
  2689.           ╤    Must be  fast.   It should  not take  more than 5 seconds to
  2690.           decompress a  100K byte  grayscale image on a 68020- or 386-based
  2691.           computer.   Compression can  be slower,  but probably not by more
  2692.           than a factor of 2 or 3.
  2693.           ╤    The level  of implementation  complexity must be reasonable.
  2694.           We would like something that can be implemented in no more than a
  2695.           couple of  weeks  by  a_competent  software  engineer  with  some
  2696.           experience  in   image  processing.     The   compiled  code  for
  2697.           compression and  decompression combined  should be  no more  than
  2698.           about 10K.
  2699.           ╤    Does not require floating point software or hardware.
  2700.           
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.           TIFF 5.0                                          page 42          TIFF 5.0                                          page 42
  2711.  
  2712.  
  2713.           
  2714.           The following  sections describe  an algorithm based on the _LZW_
  2715.           (Lempel-Ziv & Welch) technique that meets the above requirements.
  2716.           In addition  meeting our  requirements,  LZW  has  the  following
  2717.           characteristics:
  2718.           
  2719.           ╤    LZW is fully reversible.  All information is preserved.  But
  2720.           if noise  or information  is removed  from an  image, perhaps  by
  2721.           smoothing or  zeroing some  low-order bitplanes,  LZW  compresses
  2722.           images to  a smaller  size.   Thus,   5-bit, 6-bit, or 7-bit data
  2723.           masquerading as  8-bit data  compresses better  than  true  8-bit
  2724.           data. Smooth  images also  compress better than noisy images, and
  2725.           simple images compress better than complex images.
  2726.           φ    On a  68082- or  386-based computer,  LZW  software  can  be
  2727.           written to  compress at  between 30K  and 80K  bytes per  second,
  2728.           depending on image characteristics.  LZW decompression speeds are
  2729.           typically about 50K bytes per second.
  2730.           φ    LZW works  well on  bilevel images,  too.   It always  beats
  2731.           PackBits,  and   generally  ties   CCITT  1D  (Modified  Huffman)
  2732.           compression, on our test images.  Tying CCITT 1D is impressive in
  2733.           that LZW  seems to be considerably faster than CCITT 1D, at least
  2734.           in our implementation.
  2735.           φ    Our implementation is written in C, and compiles to about 2K
  2736.           bytes of object code each for the compressor and decompressor.
  2737.           φ    One of  the nice  things about  LZW is that it is used quite
  2738.           widely in  other applications  such as  archival programs, and is
  2739.           therefore more of a known quantity.
  2740.           
  2741.           
  2742.           The Algorithm
  2743.           
  2744.           Each strip  is compressed  independently.   We strongly recommend
  2745.           that RowsPerStrip  be chosen  such that each strip contains about
  2746.           8K bytes  before compression.   We  want to keep the strips small
  2747.           enough so  that the  compressed and  uncompressed versions of the
  2748.           strip can  be kept entirely in memory even on small machines, but
  2749.           large enough to maintain nearly optimal compression ratios.
  2750.           
  2751.           The LZW  algorithm is  based on  a translation  table, or  string
  2752.           table, that  maps strings  of input  characters into  codes.  The
  2753.           TIFF implementation  uses variable-length  codes, with  a maximum
  2754.           code length of 12 bits.  This string table is different for every
  2755.           strip, and,  remarkably, does  not need to be kept around for the
  2756.           decompressor.     The  trick   is  to   make   the   decompressor
  2757.           automatically build  the same  table as is built when compressing
  2758.           the data.   We  use a  C-like pseudocode  to describe  the coding
  2759.           scheme:
  2760.           
  2761.                InitializeStringTable();
  2762.                WriteCode(ClearCode);
  2763.                _ = the empty string;
  2764.                for each character in the strip {
  2765.                     K = GetNextCharacter();
  2766.                     if _+K is in the string table {
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.           TIFF 5.0                                          page 43          TIFF 5.0                                          page 43
  2777.  
  2778.  
  2779.                          _ = _+K;  /* string concatenation */
  2780.                     } else {
  2781.                          WriteCode (CodeFromString(_));
  2782.                          AddTableEntry(_+K);
  2783.                          _ = K;
  2784.                     }
  2785.                } /* end of for loop */
  2786.                WriteCode (CodeFromString(_));
  2787.                WriteCode (EndOfInformation);
  2788.                     
  2789.           That_s  it.    The  scheme  is  simple,  although  it  is  fairly
  2790.           challenging  to  implement  efficiently.    But  we  need  a  few
  2791.           explanations before we go on to decompression.
  2792.           
  2793.           The  _characters_   that  make  up  the  LZW  strings  are  bytes
  2794.           containing TIFF  uncompressed (Compression=1)  image data, in our
  2795.           implementation.   For example,  if BitsPerSample is 4, each 8-bit
  2796.           LZW character will contain two 4-bit pixels.  If BitsPerSample is
  2797.           16, each 16-bit pixel will span two 8-bit LZW characters.
  2798.           
  2799.           (It is  also possible to implement a version of LZW where the LZW
  2800.           character depth equals BitsPerSample, as was described by Draft 2
  2801.           of Revision  5.0.   But  there  is  a  major  problem  with  this
  2802.           approach.   If BitsPerSample  is greater  than 11, we can not use
  2803.           12-bit-maximum  codes,   so  that  the  resulting  LZW  table  is
  2804.           unacceptably large.   Fortunately,  due to the adaptive nature of
  2805.           LZW, we  do not  pay a  significant compression ratio penalty for
  2806.           combining several  pixels into  one byte before compressing.  For
  2807.           example, our  4-bit sample  images  compressed  about  3  percent
  2808.           worse, and  our 1-bit  images compressed  about 5 percent better.
  2809.           And it  is easier to write an LZW compressor that always uses the
  2810.           same character  depth than  it is  to write  one which can handle
  2811.           varying depths.)
  2812.           
  2813.           We can  now describe  some of the routine and variable references
  2814.           in our pseudocode:
  2815.           
  2816.           InitializeStringTable() initializes  the string  table to contain
  2817.           all possible  single-character strings.   There  are 256 of them,
  2818.           numbered 0 through 255, since our characters are bytes.
  2819.           
  2820.           WriteCode() writes  a code  to the output stream.  The first code
  2821.           written is a Clear code, which is defined to be code #256.
  2822.           
  2823.           _ is our _prefix string._
  2824.           
  2825.           GetNextCharacter() retrieves  the next  character value  from the
  2826.           input stream.   This  will be number between 0 and 255, since our
  2827.           characters are bytes.
  2828.           
  2829.           The _+_ signs indicate string concatenation.
  2830.           
  2831.           AddTableEntry() adds a table entry.  (InitializeStringTable() has
  2832.           already put  256 entries  in our table.  Each entry consists of a
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.           TIFF 5.0                                          page 44          TIFF 5.0                                          page 44
  2843.  
  2844.  
  2845.           single-character string, and its associated code value, which is,
  2846.           in our  application, identical to the character itself.  That is,
  2847.           the 0th  entry in  our table  consists of  the string  <0>,  with
  2848.           corresponding code  value of  <0>, the  1st entry  in  the  table
  2849.           consists of the string <1>, with corresponding code value of <1>,
  2850.           ..., and  the 255th  entry in  our table  consists of  the string
  2851.           <255>, with  corresponding code  value of  <255>.)   So the first
  2852.           entry that  we add  to our  string table will be at position 256,
  2853.           right?   Well, not  quite, since  we will reserve code #256 for a
  2854.           special   _Clear_   code,   and   code   #257   for   a   special
  2855.           _EndOfInformation_ code  that we will write out at the end of the
  2856.           strip.  So the first multiple-character entry added to the string
  2857.           table will be at position 258.
  2858.           
  2859.           Let_s try  an example.   Suppose  we have  input data  that looks
  2860.           like:
  2861.           
  2862.           Pixel 0:  <7>
  2863.           Pixel 1:  <7>
  2864.           Pixel 2:  <7>
  2865.           Pixel 3:  <8>
  2866.           Pixel 4:  <8>
  2867.           Pixel 5:  <7>
  2868.           Pixel 6:  <7>
  2869.           Pixel 7:  <6>
  2870.           Pixel 8:  <6>
  2871.           
  2872.           First, we read Pixel 0 into K.  _K is then simply <7>, since _ is
  2873.           the empty string at this point.  Is the string <7> already in the
  2874.           string table?  Of course, since all single character strings were
  2875.           put in  the table  by InitializeStringTable().  So set _ equal to
  2876.           <7>, and go to the top of the loop.
  2877.           
  2878.           Read Pixel 1 into K.  Does _K (<7><7>) exist in the string table?
  2879.           No, so we get to do some real work.  We write the code associated
  2880.           with _  to output  (write <7>  to output), and add _K (<7><7>) to
  2881.           the table  as entry  258.   Store K  (<7>) into  _.    Note  that
  2882.           although we have added the string consisting of Pixel 0 and Pixel
  2883.           1 to  the table, we _re-use_ Pixel 1 as the beginning of the next
  2884.           string.
  2885.           
  2886.           Back at  the top  of the  loop.  We read Pixel 2 into K.  Does _K
  2887.           (<7><7>) exist  in the  string table?   Yes,  the entry  we  just
  2888.           added, entry 258, contains exactly <7><7>.  So we just add K onto
  2889.           the end of _, so that _ is now <7><7>.
  2890.           
  2891.           Back at  the top  of the  loop.  We read Pixel 3 into K.  Does _K
  2892.           (<7><7><8>) exist  in the  string table?   No,  so write the code
  2893.           associated with  _ (<258>)  to output, and add _K to the table as
  2894.           entry 259.  Store K (<8>) into _.
  2895.           
  2896.           Back at  the top  of the  loop.  We read Pixel 4 into K.  Does _K
  2897.           (<8><8>) exist  in the  string table?   No,  so  write  the  code
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.           TIFF 5.0                                          page 45          TIFF 5.0                                          page 45
  2909.  
  2910.  
  2911.           associated with  _ (<8>)  to output,  and add  _K to the table as
  2912.           entry 260.  Store K (<8>) into _.
  2913.           
  2914.           Continuing, we get the following results:
  2915.           
  2916.                After reading: We write to output: And add table entry:
  2917.                Pixel 0
  2918.                Pixel 1   <7>  258: <7><7>
  2919.                Pixel 2
  2920.                Pixel 3   <258>     259: <7><7><8>
  2921.                Pixel 4   <8>  260: <8><8>
  2922.                Pixel 5   <8>  261: <8><7>
  2923.                Pixel 6
  2924.                Pixel 7   <258>     262: <7><7><6>
  2925.                Pixel 8   <6>  263: <6><6>
  2926.           
  2927.           WriteCode() also  requires some  explanation.   The  output  code
  2928.           stream,  <7><258><8><8><258><6>...  in  our  example,  should  be
  2929.           written using as few bits as possible.  When we are just starting
  2930.           out, we  can use  9-bit codes, since our new string table entries
  2931.           are greater  than 255  but less  than 512.  But when we add table
  2932.           entry 512,  we must  switch to 10-bit codes.  Likewise, we switch
  2933.           to 11-bit  codes at  1024, and  12-bit codes  at 2048.   We  will
  2934.           somewhat arbitrarily limit ourselves to 12-bit codes, so that our
  2935.           table can  have at most 4096 entries.  If we push it any farther,
  2936.           tables tend to get too large.
  2937.           
  2938.           What happens  if we run out of room in our string table?  This is
  2939.           where the afore-mentioned Clear code comes in.  As soon as we use
  2940.           entry 4094, we write out a (12-bit) Clear code.   (If we wait any
  2941.           longer to  write the  Clear code,  the decompressor  might try to
  2942.           interpret the  Clear code  as a 13-bit code.)  At this point, the
  2943.           compressor re-initializes the string table and starts writing out
  2944.           9-bit codes again.
  2945.           
  2946.           Note that  whenever you  write a code and add a table entry, _ is
  2947.           not left  empty.   It contains exactly one character.  Be careful
  2948.           not to  lose it  when you  write an end-of-table Clear code.  You
  2949.           can either write it out as a 12-bit code before writing the Clear
  2950.           code, in  which case  you will  want to  do it right after adding
  2951.           table entry  4093, or  after the  clear code  as  a  9-bit  code.
  2952.           Decompression gives the same result in either case.
  2953.           
  2954.           To make  things a  little simpler  for the  decompressor, we will
  2955.           require that  each strip  begins with a Clear code, and ends with
  2956.           an EndOfInformation code.
  2957.           
  2958.           Every LZW-compressed  strip must  begin on  a byte  boundary.  It
  2959.           need not  begin on  a word  boundary.   LZW compression codes are
  2960.           stored into  bytes in  high-to-low-order fashion, i.e., FillOrder
  2961.           is assumed  to be  1.  The compressed codes are written as bytes,
  2962.           not  words,  so  that  the  compressed  data  will  be  identical
  2963.           regardless of whether it is an _II_ or _MM_ file.
  2964.           
  2965.  
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.           TIFF 5.0                                          page 46          TIFF 5.0                                          page 46
  2975.  
  2976.  
  2977.           Note that  the LZW string table is a continuously updated history
  2978.           of the  strings that  have been encountered in the data.  It thus
  2979.           reflects the characteristics of the data, providing a high degree
  2980.           of adaptability.
  2981.           
  2982.           
  2983.           LZW Decoding
  2984.           
  2985.           The procedure for decompression is a little more complicated, but
  2986.           still not too bad:
  2987.                     
  2988.                while ((Code = GetNextCode()) != EoiCode) {
  2989.                     if (Code == ClearCode) {
  2990.                          InitializeTable();
  2991.                          Code = GetNextCode();
  2992.                          if (Code == EoiCode)
  2993.                               break;
  2994.                          WriteString(StringFromCode(Code));
  2995.                          OldCode = Code;
  2996.                     }  /* end of ClearCode case */
  2997.           
  2998.                     else {
  2999.                          if (IsInTable(Code)) {
  3000.                               WriteString(StringFromCode(Code));
  3001.                               AddStringToTable(StringFromCode(OldCode)+Firs
  3002.           tChar(StringFromCode(Code)));
  3003.                               OldCode = Code;
  3004.                          } else {
  3005.                               OutString   =    StringFromCode(OldCode)    +
  3006.           FirstChar(StringFromCode(OldCode));
  3007.                               WriteString(OutString);
  3008.                               AddStringToTable(OutString);
  3009.                               OldCode = Code;
  3010.                          }
  3011.                     } /* end of not-ClearCode case */
  3012.                } /* end of while loop */
  3013.           
  3014.           The function  GetNextCode() retrieves the next code from the LZW-
  3015.           coded data.  It must keep track of bit boundaries.  It knows that
  3016.           the first code that it gets will be a 9-bit code.  We add a table
  3017.           entry each  time we get a code, so GetNextCode() must switch over
  3018.           to 10-bit codes as soon as string #511 is stored into the table.
  3019.           
  3020.           The function  StringFromCode() gets  the string associated with a
  3021.           particular code from the string table.
  3022.           
  3023.           The function  AddStringToTable() adds  a  string  to  the  string
  3024.           table.   The _+_  sign joining  the two  parts of the argument to
  3025.           AddStringToTable indicate string concatenation.
  3026.           
  3027.           StringFromCode() looks  up the  string associated  with  a  given
  3028.           code.
  3029.           
  3030.           WriteString() adds a string to the output stream.
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.           TIFF 5.0                                          page 47          TIFF 5.0                                          page 47
  3041.  
  3042.  
  3043.           
  3044.           
  3045.           When SamplesPerPixel Is Greater Than 1
  3046.           
  3047.           We  have   so  far   described  the   compression  scheme  as  if
  3048.           SamplesPerPixel were  always 1,  as will  be  be  the  case  with
  3049.           palette color  and grayscale  images.  But what do we do with RGB
  3050.           image data?
  3051.           
  3052.           Tests on  our sample  images indicate  that the  LZW  compression
  3053.           ratio    is    nearly    identical    regardless    of    whether
  3054.           PlanarConfiguration=1 or  PlanarConfiguration=2, for  RGB images.
  3055.           So use  whichever configuration  you prefer,  and simply compress
  3056.           the bytes in the strip.
  3057.           
  3058.           It is  worth cautioning  that compression  ratios on our test RGB
  3059.           images were disappointing low: somewhere between 1.1 to 1 and 1.5
  3060.           to 1,  depending on the image.  Vendors are urged to do what they
  3061.           can to  remove as  much noise  from  their  images  as  possible.
  3062.           Preliminary tests  indicate that significantly better compression
  3063.           ratios are  possible with  less noisy  images.  Even something as
  3064.           simple as  zeroing out one or two least-significant bitplanes may
  3065.           be  quite   effective,  with   little  or  no  perceptible  image
  3066.           degradation.
  3067.           
  3068.           
  3069.           Implementation
  3070.           
  3071.           The exact  structure of  the string  table and the method used to
  3072.           determine if  a string  is already  in the table are probably the
  3073.           most significant  design decisions in the implementation of a LZW
  3074.           compressor and  decompressor.   Hashing has  been suggested  as a
  3075.           useful technique for the compressor.  We have chosen a tree based
  3076.           approach, with  good results.   The decompressor is actually more
  3077.           straightforward,  as   well  as   faster,  since   no  search  is
  3078.           involved_strings can be accessed directly by code value.
  3079.           
  3080.           
  3081.           Performance
  3082.           
  3083.           Many  people   do  not   realize  that  the  performance  of  any
  3084.           compression scheme  depends greatly  on the type of data to which
  3085.           it is  applied.   A scheme that works well on one data set may do
  3086.           poorly on the next.
  3087.           
  3088.           But since  we do  not want  to burden  the world  with  too  many
  3089.           compression schemes, an adaptive scheme such as LZW that performs
  3090.           quite well  on a wide range of images is very desirable.  LZW may
  3091.           not always  give optimal  compression ratios,  but  its  adaptive
  3092.           nature and relative simplicity seem to make it a good choice.
  3093.           
  3094.           Experiments thus  far indicate  that we  can  expect  compression
  3095.           ratios of  between 1.5  and 3.0  to 1  from LZW,  with no loss of
  3096.           data, on  continuous tone  grayscale scanned  images.  If we zero
  3097.  
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.           TIFF 5.0                                          page 48          TIFF 5.0                                          page 48
  3107.  
  3108.  
  3109.           the least  significant one or two bitplanes of 8-bit data, higher
  3110.           ratios can be achieved.  These bitplanes often consist chiefly of
  3111.           noise, in  which case  little or no loss in image quality will be
  3112.           perceived.   Palette color  images created  in  a  paint  program
  3113.           generally compress  much  better  than  continuous  tone  scanned
  3114.           images, since paint images tend to be more repetitive.  It is not
  3115.           unusual to  achieve compression  ratios of 10 to 1 or better when
  3116.           using LZW on palette color paint images.
  3117.           
  3118.           By way  of comparison, PackBits, used in TIFF for black and white
  3119.           bilevel images, does not do well on color paint images, much less
  3120.           continuous tone  grayscale and  color images.  1.2 to 1 seemed to
  3121.           be about average for 4-bit images, and 8-bit images are worse.
  3122.           
  3123.           It has  been suggested that the CCITT 1D scheme could be used for
  3124.           continuous tone  images, by compressing each bitplane separately.
  3125.           No doubt  some  compression  could  be  achieved,  but  it  seems
  3126.           unlikely that  a scheme  based on a fixed table that is optimized
  3127.           for short  black runs  separated by  longer white runs would be a
  3128.           very good choice on any of the bitplanes.  It would do quite well
  3129.           on the  high-order bitplanes  (but so would a simpler scheme like
  3130.           PackBits), and  would do quite poorly on the low-order bitplanes.
  3131.           We believe  that the  compression ratios  would generally  not be
  3132.           very impressive, and the process would in addition be quite slow.
  3133.           Splitting  the  pixels  into  bitplanes  and  putting  them  back
  3134.           together is  somewhat expensive,  and the  coding is  also fairly
  3135.           slow when implemented in software.
  3136.           
  3137.           Another  approach   that  has  been  suggested  uses  uses  a  2D
  3138.           differencing step  following by  coding the  differences using  a
  3139.           fixed table  of variable-length codes.  This type of scheme works
  3140.           quite well  on many  8-bit  grayscale  images,  and  is  probably
  3141.           simpler  to  implement  than  LZW.    But  it  has  a  number  of
  3142.           disadvantages when  used on  a wide variety of images.  First, it
  3143.           is not  adaptive.   This makes  a big difference when compressing
  3144.           data such as 8-bit images that have been _sharpened_ using one of
  3145.           the standard  techniques.  Such images tend to get larger instead
  3146.           of smaller  when  compressed.    Another  disadvantage  of  these
  3147.           schemes is  that they  do not  do well  with a  wide range of bit
  3148.           depths.   The built-in  code table  has to  be  optimized  for  a
  3149.           particular bit depth in order to be effective.
  3150.           
  3151.           Finally,  we   should  mention   _lossy_   compression   schemes.
  3152.           Extensive research  has been  done in  the area of lossy, or non-
  3153.           information-preserving  image   compression.    These  techniques
  3154.           generally yield  much  higher  compression  ratios  than  can  be
  3155.           achieved  by   fully-reversible,   information-preserving   image
  3156.           compression  techniques   such  as   PackBits  and   LZW.    Some
  3157.           disadvantages:     many  of   the   lossy   techniques   are   so
  3158.           computationally expensive  that hardware  assists  are  required.
  3159.           Others  are  so  complicated  that  most  microcomputer  software
  3160.           vendors could  not afford either the expense of implementation or
  3161.           the increase  in  application  object  code  size.    Yet  others
  3162.  
  3163.  
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.           TIFF 5.0                                          page 49          TIFF 5.0                                          page 49
  3173.  
  3174.  
  3175.           sacrifice enough  image  quality  to  make  them  unsuitable  for
  3176.           publishing use.
  3177.           
  3178.           In spite  of these  difficulties, we  believe that there will one
  3179.           day be  a standardized  lossy compression  scheme for  full color
  3180.           images  that  will  be  usable  for  publishing  applications  on
  3181.           microcomputers.   An International  Standards Organization group,
  3182.           ISO/IEC/JTC1/SC2/WG8, in cooperation with CCITT Study Group VIII,
  3183.           is hard at work on a scheme that might be appropriate.  We expect
  3184.           that a  future revision of TIFF will incorporate this scheme once
  3185.           it is  finalized, if it turns out to satisfy the needs of desktop
  3186.           publishers and  others in the microcomputer community.  This will
  3187.           augment, not replace, LZW as an approved TIFF compression scheme.
  3188.           LZW will  very likely  remain the  scheme of  choice for  Palette
  3189.           color images,  and perhaps  4-bit grayscale  images, and may well
  3190.           overtake CCITT 1D and PackBits for bilevel images.
  3191.           
  3192.           
  3193.           Future LZW Extensions
  3194.           
  3195.           Some images  compress better  using LZW  coding if they are first
  3196.           subjected to  a process  wherein each  pixel value is replaced by
  3197.           the  difference  between  the  pixel  and  the  preceding  pixel.
  3198.           Performing this  differencing in two dimensions helps some images
  3199.           even more.  However, many images do not compress better with this
  3200.           extra preprocessing,  and for a significant number of images, the
  3201.           compression ratio is actually worse.  We are therefore not making
  3202.           differencing an integral part of the TIFF LZW compression scheme.
  3203.           
  3204.           However,  it   is  possible   that  a   _prediction_  stage  like
  3205.           differencing may  exist which  is effective over a broad range of
  3206.           images.  If such a scheme is found, it may be incorporated in the
  3207.           next major TIFF revision.  If so, a new value will be defined for
  3208.           the new  _Predictor_ TIFF  tag.  Therefore, all TIFF readers that
  3209.           read LZW files must pay attention to the Predictor tag.  If it is
  3210.           1, which  is the  default case,  LZW  decompression  may  proceed
  3211.           safely.   If it  is not  1, and the reader does not recognize the
  3212.           specified prediction scheme, the reader should give up.
  3213.           
  3214.           
  3215.           Acknowledgements
  3216.           
  3217.           The original  LZW reference  has already  been given.  The use of
  3218.           ClearCode as a technique to handle overflow was borrowed from the
  3219.           compression scheme used by the Graphics Interchange Format (GIF),
  3220.           a small-color-paint-image-file  format used  by  CompuServe  that
  3221.           also is an adaptation of the LZW technique.  Joff Morgan and Eric
  3222.           Robinson of  Aldus were  each instrumental  in their  own way  in
  3223.           getting LZW off the ground.
  3224.           
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.           TIFF 5.0                                          page 50          TIFF 5.0                                          page 50
  3239.  
  3240.  
  3241.           Appendix G: TIFF Classes
  3242.           
  3243.           
  3244.           Rationale
  3245.           
  3246.           TIFF was  designed to  make  life  easier  for  scanner  vendors,
  3247.           desktop publishing  software developers,  and users  of these two
  3248.           classes of products, by reducing the proliferation of proprietary
  3249.           scanned  image   formats.    It  has  succeeded  far  beyond  our
  3250.           expectations in  this respect.   But  we had  expected that  TIFF
  3251.           would be of interest to only a dozen or so scanner vendors (there
  3252.           weren_t any  more than  that in  1985), and  another dozen  or so
  3253.           desktop publishing  software vendors.   This  turned out  to be a
  3254.           gross underestimate.   The only problem with this sort of success
  3255.           is that  TIFF was  designed to  be powerful  and flexible, at the
  3256.           expense of  simplicity.   It takes  a fair  amount of  effort  to
  3257.           handle all  the options  currently defined  in this specification
  3258.           (probably no  application does  a  complete  job),  and  that  is
  3259.           currently the  only way  you can be sure that you will be able to
  3260.           import any  TIFF image,  since there are so many image-generating
  3261.           applications out there now.
  3262.           
  3263.           So here  is an attempt to channel some of the flexibility of TIFF
  3264.           into more  restrictive paths,  using what  we have learned in the
  3265.           past two  years about which options are the most useful.  Such an
  3266.           undertaking is  of course filled with fairly arbitrary decisions.
  3267.           But the  result is  that writers can more easily write files that
  3268.           will be  successfully read by a wide variety of applications, and
  3269.           readers can know when they can stop adding TIFF features.
  3270.           
  3271.           The price  we pay for TIFF Classes is some loss in the ability to
  3272.           adapt.   Once we  establish the requirements for a TIFF Class, we
  3273.           can never add new requirements, since old software would not know
  3274.           about these  new requirements.  (The best we can do at that point
  3275.           is establish new TIFF Classes.  But the problem with that is that
  3276.           we could quickly have too many TIFF Classes.)  So we must believe
  3277.           that we know what we are doing in establishing these Classes.  If
  3278.           we do not, any mistakes will be expensive.
  3279.           
  3280.           
  3281.           Overview
  3282.           
  3283.           Four TIFF Classes have been defined:
  3284.           
  3285.           ╤    Class B for bilevel (1-bit) images
  3286.           ╤    Class G for grayscale images
  3287.           ╤    Class P for palette color images
  3288.           ╤    Class R for RGB full color images
  3289.           
  3290.           To save  time and  space, we will usually say _TIFF B_, _TIFF G_,
  3291.           _TIFF P,_  and _TIFF R._  If we are talking about all four types,
  3292.           we may write _TIFF X._
  3293.           
  3294.  
  3295.  
  3296.  
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.           TIFF 5.0                                          page 51          TIFF 5.0                                          page 51
  3305.  
  3306.  
  3307.           (Note to  fax people:   if  you are  interested in  a fax  TIFF F
  3308.           Class, please  get together  and decide  what should  be in  TIFF
  3309.           Class F  files.  Let us know if we can help in any way.  When you
  3310.           have decided,  send us  your results,  so that we can include the
  3311.           information here.)
  3312.           
  3313.           
  3314.           Core Requirements
  3315.           
  3316.           This section  describes requirements  that are common to all TIFF
  3317.           Class X images.
  3318.           
  3319.           General Requirements
  3320.           
  3321.           The following  are required  characteristics of  all TIFF Class X
  3322.           files.
  3323.           
  3324.           Where there are options, TIFF X writers can do whichever one they
  3325.           want, though  we will  often recommend  a particular  choice, but
  3326.           TIFF X  readers must  be able  to handle all of them.  Please pay
  3327.           close attention  to the  recommendations.  It is possible that at
  3328.           some point  in the future, new and even-simpler TIFF classes will
  3329.           be defined that include only recommended features.
  3330.           
  3331.           You will  need to  read at  least the first three sections of the
  3332.           main specification  in order  to fully  understand the  following
  3333.           discussion.
  3334.           
  3335.           Defaults.  TIFF X writers may, but are not required, to write out
  3336.           a field that has a default value, if the default value is the one
  3337.           desired.   TIFF X  readers must  be  prepared  to  handle  either
  3338.           situation.
  3339.           
  3340.           Other fields.   TIFF  X readers  must be  prepared  to  encounter
  3341.           fields other  than the  required fields  in TIFF X files.  TIFF X
  3342.           writers  are  allowed  to  write  fields  such  as  Make,  Model,
  3343.           DateTime, and so on, and TIFF X readers can certainly make use of
  3344.           such fields  if they  exist.   TIFF X  readers must not, however,
  3345.           refuse to read the file if such optional fields do not exist.
  3346.           
  3347.           _MM_ and  æIIÆ byte order.  TIFF X readers must be able to handle
  3348.           both byte  orders.    TIFF  writers  can  do  whichever  is  most
  3349.           convenient  or   efficient.     Images  are   crossing  the   IBM
  3350.           PC/Macintosh boundary  (and others  as well)  with a surprisingly
  3351.           high frequency.   We could force writers to all use the same byte
  3352.           order, but  preliminary evidence  indicates that  this will cause
  3353.           problems  when   we  start   seeing  greater-than-8-bit   images.
  3354.           Reversing bytes  while scanning could well slow down the scanning
  3355.           process enough  to cause  the scanning  mechanism to  stop, which
  3356.           tends to create image quality problems.
  3357.           
  3358.           Multiple subfiles.   TIFF X readers must be prepared for multiple
  3359.           images (i.e.,  subfiles) per  TIFF file,  although they  are  not
  3360.           required to do anything with any image after the first one.  TIFF
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.           TIFF 5.0                                          page 52          TIFF 5.0                                          page 52
  3371.  
  3372.  
  3373.           X writers  must be  sure to write a long word of 0 after the last
  3374.           IFD (this is the standard way of signalling that this IFD was the
  3375.           last one) as indicated in the TIFF structure discussion.
  3376.           
  3377.           If a  TIFF X  writer writes multiple subfiles, the first one must
  3378.           be the  full resolution  image.   Subsequent subimages,  such  as
  3379.           reduced resolution  images and  transparency masks, may be in any
  3380.           order in  the TIFF  file.   If a reader wants to make use of such
  3381.           subimages, it  will have to scan the IFDÆs before deciding how to
  3382.           proceed.
  3383.           
  3384.           TIFF X  Editors.   Editors, applications  that modify TIFF files,
  3385.           have a few additional requirements.
  3386.           
  3387.           TIFF editors  must be  especially careful  about subfiles.   If a
  3388.           TIFF editor  edits a full-resolution subfile, but does not update
  3389.           an accompanying  reduced-resolution subfile,  a reader  that uses
  3390.           the reduced-resolution  subfile for  screen display  will display
  3391.           the wrong  thing.   So TIFF  editors must  either  create  a  new
  3392.           reduced-resolution subfile  when  they  alter  a  full-resolution
  3393.           subfile, or  else they  must simply delete any subfiles that they
  3394.           aren_t prepared to deal with.
  3395.           
  3396.           A similar  situation arises with the fields themselves.  A TIFF X
  3397.           editor need  only worry  about the  TIFF X  required fields.   In
  3398.           particular, it  is unnecessary,  and probably  dangerous, for  an
  3399.           editor to  copy fields  that it does not understand.  It may have
  3400.           altered the  file in  a way that is incompatible with the unknown
  3401.           fields.
  3402.           
  3403.           
  3404.           Required Fields
  3405.           
  3406.           NewSubfileType.  LONG.  Recommended but not required.
  3407.           
  3408.           ImageWidth.   SHORT or  LONG.   (That is, both _SHORT_ and _LONG_
  3409.           TIFF data  types are  allowed, and  must be  handled properly  by
  3410.           readers.   TIFF writers  can use either.)  TIFF X readers are not
  3411.           required to  read arbitrarily  large files however.  Some readers
  3412.           will give  up if the entire image cannot fit in available memory.
  3413.           (In such cases the reader should inform the user of the nature of
  3414.           the problem.)   Others  will  probably  not  be  able  to  handle
  3415.           ImageWidth greater  than 65535.   Recommendation: use LONG, since
  3416.           resolutions seem to keep going up.
  3417.           
  3418.           ImageLength.  SHORT or LONG.  Recommendation: use  LONG.
  3419.           
  3420.           RowsPerStrip.  SHORT or LONG.  Readers must be able to handle any
  3421.           value between  1 and  2**32-1.   However, some readers may try to
  3422.           read an  entire strip  into memory  at one  time, so  that if the
  3423.           entire image is one strip, the application may run out of memory.
  3424.           Recommendation 1:   Set  RowsPerStrip such  that the size of each
  3425.           strip is  about 8K  bytes.   Do this  even for uncompressed data,
  3426.           since it  is easy  for a  writer and  makes  things  simpler  for
  3427.  
  3428.  
  3429.  
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.           TIFF 5.0                                          page 53          TIFF 5.0                                          page 53
  3437.  
  3438.  
  3439.           readers.  (Note:  extremely wide, high-resolution images may have
  3440.           rows larger  than 8K  bytes; in this case, RowsPerStrip should be
  3441.           1,  and   the  strip  will  just  have  to  be  larger  than  8K.
  3442.           Recommendation 2: use LONG.
  3443.           
  3444.           StripOffsets.   SHORT or  LONG.  As explained in the main part of
  3445.           the  specification,   the  number   of  StripOffsets  depends  on
  3446.           RowsPerStrip and  ImageLength.  Recommendation:  always use LONG.
  3447.           (LONG must, of course, be used if the file is more than 64K bytes
  3448.           in length.)
  3449.           
  3450.           StripByteCounts.   SHORT or  LONG.   Many existing TIFF images do
  3451.           not contain StripByteCounts, because, in a strict sense, they are
  3452.           unnecessary.   It is  possible to  write an efficient TIFF reader
  3453.           that does  not need  to know  in advance  the  exact  size  of  a
  3454.           compressed strip.   But  it does  make things  considerably  more
  3455.           complicated, so  we will require StripByteCounts in TIFF X files.
  3456.           Recommendation:   use SHORT,  since strips are not supposed to be
  3457.           very large.
  3458.           
  3459.           XResolution, YResolution.   RATIONAL.   Note  that the  X  and  Y
  3460.           resolutions may  be unequal.   A  TIFF X  reader must  be able to
  3461.           handle this  case.   TIFF X pixel-editors will typically not care
  3462.           about the  resolution,  but  applications  such  as  page  layout
  3463.           programs will.
  3464.           
  3465.           ResolutionUnit.   SHORT.   TIFF X  readers must  be  prepared  to
  3466.           handle all three values for ResolutionUnit.
  3467.           
  3468.           
  3469.           TIFF Class B - Bilevel
  3470.           
  3471.           Required (in addition to the above core requirements)
  3472.           
  3473.           The following fields and values are required for TIFF B files, in
  3474.           addition to  the fields  required for  all  TIFF  X  images  (see
  3475.           above).
  3476.           
  3477.           SamplesPerPixel =  1.   SHORT.   (Since this  is the default, the
  3478.           field need  not be  present.   The same  thing  holds  for  other
  3479.           required TIFF X fields that have defaults.)
  3480.           
  3481.           BitsPerSample = 1.  SHORT.
  3482.           
  3483.           Compression = 1, 2 (CCITT 1D), or 32773 (PackBits).  SHORT.  TIFF
  3484.           B readers  must handle all three.  Recommendation:  use PackBits.
  3485.           It  is  simple,  effective,  fast,  and  has  a  good  worst-case
  3486.           behavior.    CCITT  1D  is  definitely  more  effective  in  some
  3487.           situations, such as scanning a page of body text, but is tough to
  3488.           implement and  test, fairly  slow,  and  has  a  poor  worst-case
  3489.           behavior.   Besides, scanning a page of 12 point text is not very
  3490.           useful for  publishing applications,  unless the  image  data  is
  3491.           turned into  ASCII text  via OCR  software, which  is outside the
  3492.           scope of TIFF.
  3493.  
  3494.  
  3495.  
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.           TIFF 5.0                                          page 54          TIFF 5.0                                          page 54
  3503.  
  3504.  
  3505.           
  3506.           PhotometricInterpretation = 0 or 1.  SHORT.
  3507.           A Sample TIFF B Image
  3508.           
  3509.           Offset         Value
  3510.           (hex)     Name (mostly hex)
  3511.           
  3512.           Header:
  3513.           0000 Byte Order     4D4D
  3514.           0002 Version   002A
  3515.           0004 1st IFD pointer     00000014
  3516.           
  3517.           IFD:
  3518.           0014 Entry Count    000D
  3519.           0016 NewSubfileType 00FE 0004 00000001  00000000
  3520.           0022 ImageWidth     0100 0004 00000001  000007D0
  3521.           002E ImageLength    0101 0004 00000001  00000BB8
  3522.           003A Compression    0103 0003 00000001  8005 0000
  3523.           0046 PhotometricInterpretation     0106 0003 00000001  0001 0000
  3524.           0052 StripOffsets   0111 0004 000000BC  000000B6
  3525.           005E RowsPerStrip   0116 0004 00000001  00000010
  3526.           006A StripByteCounts     0117 0003 000000BC  000003A6
  3527.           0076 XResolution    011A 0005 00000001  00000696
  3528.           0082 YResolution    011B 0005 00000001  0000069E
  3529.           008E Software  0131 0002 0000000E  000006A6
  3530.           009A DateTime  0132 0002 00000014  000006B6
  3531.           00A6 Next IFD pointer    00000000
  3532.           
  3533.           Fields pointed to by the tags:
  3534.           00B6 StripOffsets   Offset0, Offset1, ... Offset187
  3535.           03A6 StripByteCounts     Count0, Count1, ... Count187
  3536.           0696 XResolution    0000012C 00000001
  3537.           069E YResolution    0000012C 00000001
  3538.           06A6 Software  "PageMaker 3.0"
  3539.           06B6 DateTime  "1988:02:18 13:59:59"
  3540.           
  3541.           
  3542.           Image Data:
  3543.           00000700  Compressed data for strip 10
  3544.           xxxxxxxx  Compressed data for strip 179
  3545.           xxxxxxxx  Compressed data for strip 53
  3546.           xxxxxxxx  Compressed data for strip 160
  3547.           .
  3548.           .
  3549.           .
  3550.           
  3551.           End of example
  3552.           
  3553.           Comments on the TIFF B example
  3554.           
  3555.           1.   The IFD  in our example starts at position hex 14.  It could
  3556.           have been  anywhere in  the file  as long as the position is even
  3557.           and greater  than or equal to 8, since the TIFF header is 8 bytes
  3558.           long and must be the first thing in a TIFF file.
  3559.  
  3560.  
  3561.  
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.           TIFF 5.0                                          page 55          TIFF 5.0                                          page 55
  3569.  
  3570.  
  3571.           
  3572.           2.   With 16 rows per strip, we have 188 strips in all.
  3573.           
  3574.           3.   The example  uses a  number  of  optional  fields,  such  as
  3575.           DateTime.   TIFF X  readers must safely skip over these fields if
  3576.           they do not want to use the information.  And TIFF X readers must
  3577.           not require that such fields be present.
  3578.           
  3579.           4.   Just for  fun, our example has highly fragmented image data;
  3580.           the strips  of our  image are  not even in sequential order.  The
  3581.           point is  that strip  offsets must  not be ignored.  Never assume
  3582.           that strip  N+1 follows  strip N.    Incidentally,  there  is  no
  3583.           requirement that  the image  data follows  the  IFD  information.
  3584.           Just the follow the pointers, whether they be IFD pointers, field
  3585.           pointers, or Strip Offsets.
  3586.           
  3587.           
  3588.           
  3589.           TIFF Class G - Grayscale
  3590.           
  3591.           Required (in addition to the above core requirements)
  3592.           
  3593.           SamplesPerPixel = 1.  SHORT.
  3594.           
  3595.           BitsPerSample =  4,  8.    SHORT.    There  seems  to  be  little
  3596.           justification for  working with grayscale images shallower than 4
  3597.           bits, and 5-bit , 6-bit, and 7-bit images can easily be stored as
  3598.           8-bit images, as long as you can compress the _unused_ bit planes
  3599.           without penalty.  And we can do just that with LZW (Compression =
  3600.           5.)
  3601.           
  3602.           Compression = 1 or 5 (LZW).  SHORT.  Recommendation: use 5, since
  3603.           LZW decompression is turning out to be quite fast.
  3604.           
  3605.           PhotometricInterpretation = 0 or 1.  SHORT.   Recommendation: use
  3606.           1, due  to popular  user interfaces  for adjusting brightness and
  3607.           contrast.
  3608.           
  3609.           
  3610.           
  3611.           TIFF Class P - Palette Color
  3612.           
  3613.           Required (in addition to the above core requirements)
  3614.           
  3615.           SamplesPerPixel = 1.  SHORT.  We use each pixel value as an index
  3616.           into all three color tables in ColorMap.
  3617.           
  3618.           BitsPerSample =  1,2,3,4,5,6,7, or 8.  SHORT.  1,2,3,4, and 8 are
  3619.           probably the  most common,  but as long as we are doing that, the
  3620.           rest come pretty much for free.
  3621.           
  3622.           Compression = 1 or 5.  SHORT.
  3623.           
  3624.           PhotometricInterpretation = 3 (Palette Color).  SHORT.
  3625.  
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.           TIFF 5.0                                          page 56          TIFF 5.0                                          page 56
  3635.  
  3636.  
  3637.           
  3638.           ColorMap.  SHORT.
  3639.           
  3640.           Note that  bilevel and  grayscale images  can be  represented  as
  3641.           special cases  of palette  color images.  As soon as enough major
  3642.           applications support  palette color  images, we may want to start
  3643.           getting rid  of  distinctions  between  bilevel,  grayscale,  and
  3644.           palette color images.
  3645.           
  3646.           
  3647.           TIFF Class R - RGB Full Color
  3648.           
  3649.           Required (in addition to the above Core Requirements)
  3650.           
  3651.           SamplesPerPixel = 3.  SHORT.  One sample each for Red, Green, and
  3652.           Blue.
  3653.           
  3654.           BitsPerSample =  8,8,8.   SHORT.  Shallower samples can easily be
  3655.           stored as 8-bit samples with no penalty if the data is compressed
  3656.           with LZW.  And evidence to date indicates that images deeper than
  3657.           8 bits  per sample are not worth the extra work, even in the most
  3658.           demanding publishing applications.
  3659.           
  3660.           PlanarConfiguration = 1 or 2.  SHORT.  Recommendation:  use 1.
  3661.           
  3662.           Compression = 1 or 5.  SHORT.
  3663.           
  3664.           PhotometricInterpretation = 2 (RGB).  SHORT.
  3665.           
  3666.           Recommended
  3667.           
  3668.           Recommended for  TIFF Class  R, but not required, are the new (as
  3669.           of Revision 5.0) colorimetric information tags.  See Appendix H.
  3670.           
  3671.           
  3672.           Conformance and User Interface
  3673.           
  3674.           Applications that  write valid  TIFF X files should include _TIFF
  3675.           B_ and/or  _TIFF G_  and/or _TIFF  P_ and/or  _TIFF R_  and/or in
  3676.           their product  spec sheets, if they can write the respective TIFF
  3677.           Class X  files.   If your  application writes  all four  of these
  3678.           types, you  may wish to write it as _TIFF B,G,P,R._  Of course, a
  3679.           term like  _TIFF B,_  while fine  for  communicating  with  other
  3680.           vendors, will  not convey much information to a typical user.  In
  3681.           this case,  a  phrase  such  as  _Standard  TIFF  Black-and-White
  3682.           Scanned Images_ might be better.
  3683.           
  3684.           The same  terminology guidelines  apply to applications that read
  3685.           TIFF Class X files.
  3686.           
  3687.           If your  application reads more kinds of files than it writes, or
  3688.           vice versa,  it would  be a  good idea  to make that clear to the
  3689.           buyer.   For example, if your application reads TIFF B and TIFF G
  3690.  
  3691.  
  3692.  
  3693.  
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.           TIFF 5.0                                          page 57          TIFF 5.0                                          page 57
  3701.  
  3702.  
  3703.           files, but writes only TIFF G files, you should write it that way
  3704.           in the spec sheet.
  3705.           
  3706.  
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.           TIFF 5.0                                          page 58          TIFF 5.0                                          page 58
  3767.  
  3768.  
  3769.           Appendix H: Image Colorimetry Information
  3770.           
  3771.           Chris Sears
  3772.           210 Lake Street
  3773.           San Francisco, CA 94118
  3774.           
  3775.           June 4, 1988
  3776.           Revised August 8, 1988
  3777.           
  3778.           
  3779.           I. Introduction
  3780.           
  3781.           Our goal is to accurately reproduce a color image using different
  3782.           devices.   Accuracy requires  techniques  of  measurement  and  a
  3783.           standard  of   comparison.     Different  devices   imply  device
  3784.           independence.   Colorimetry provides the framework to solve these
  3785.           problems.  When an image has a complete colorimetric description,
  3786.           in principle  it  can  be  reproduced  identically  on  different
  3787.           monitors and using different media, such as offset lithography.
  3788.           
  3789.           The colorimetry  data is  specified when  the image is created or
  3790.           changed.   A scanned image has colorimetry data derived from  the
  3791.           filters and  light sources  of the  scanner and a synthetic image
  3792.           has colorimetry  data corresponding to the monitor used to create
  3793.           it or  the monitor model of the rendering environment.  This data
  3794.           is used  to map  an input  image to  the markings  or colors of a
  3795.           particular output device.
  3796.           
  3797.           Section II  describes various  standards organizations  and their
  3798.           work in color.
  3799.           Section III describes our motivation for seeking these tags.
  3800.           Section IV describes our goals of reproduction.
  3801.           Sections V, VI and VII introduce the colorimetry tags.
  3802.           Section VIII specifies the tags themselves.
  3803.           Section IX describes the defaults.
  3804.           Section X discusses the limitations and some of the other issues.
  3805.           Section XI provides a few references.
  3806.           
  3807.           
  3808.           II. Related Standards
  3809.           
  3810.           TIFF is  a general  standard for describing image data.  It would
  3811.           be foolish  for us  to change  TIFF in  a way  that did not match
  3812.           existing industry  and international  standards.   Therefore,  we
  3813.           have taken  pains to  note in the discussion below the efforts of
  3814.           various standards organizations and select defaults from the work
  3815.           of these organizations.
  3816.           
  3817.           CIE  (Commission Internationale de lÆEclairage)  The basis of the
  3818.           colorimetry information  is the  CIE 1931  Standard Observer [3].
  3819.           While other color models could be supported [1] [4], CIE 1931 XYZ
  3820.           is the  international standard  accepted  across  industries  for
  3821.           specifying  color   and  CIE  xyY  is  the  chromaticity  diagram
  3822.           associated with CIE 1931 XYZ tristimulus values.
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.           TIFF 5.0                                          page 59          TIFF 5.0                                          page 59
  3833.  
  3834.  
  3835.           
  3836.           NTSC (National Television  System Committee)  NTSC is of interest
  3837.           primarily  for   historical  reasons  and  its  use  in  encoding
  3838.           television data.   Manufacturing  standards for monitors have for
  3839.           some time  drifted significantly  from the  1953 NTSC colorimetry
  3840.           specification.
  3841.           
  3842.           SMPTE     (Society of  Motion Picture  and Television  Engineers)
  3843.           Most of  the work  by NTSC  has been  largely subsumed  by SMPTE.
  3844.           This organization  has a  set of  standards  called  "Recommended
  3845.           Practices" that  apply to  various technical  aspects of film and
  3846.           television production [5] [6].
  3847.           
  3848.           ISO  (International  Standards  Organization)    ISO  has  become
  3849.           involved in  color standards  through work on a color addendum to
  3850.           "Office Document Architecture (ODA) and Interchange Format" [7].
  3851.           
  3852.           ANSI (American  National   Standards  Institute)    ANSI  is  the
  3853.           American representative to ISO .
  3854.           
  3855.           
  3856.           III. Motivation
  3857.           
  3858.           Our motivation  for defining  these tags  stems from our research
  3859.           and  development  in  color  separation  technology.    With  the
  3860.           information described here and the RGB pixel data, we have all of
  3861.           the  information  necessary  for  generating  high-quality  color
  3862.           separations.  We could supply the colorimetry information outside
  3863.           of the  image  file.    But  since  TIFF  provides  a  convenient
  3864.           mechanism for  bundling all  of the  relevant  information  in  a
  3865.           single place,  tags are  defined to  describe this information in
  3866.           color TIFF files.
  3867.           
  3868.           A color  image rendered  with incorrect  colorimetry  information
  3869.           looks different  from the original.  One of our early test images
  3870.           has an artifact in it where the image was scanned with one set of
  3871.           primaries and  color ramps  were  overlaid  on  top  of  it  with
  3872.           different primaries.  The blue ramp looked purple when we printed
  3873.           it. Using incorrect gamma tables or white points can also lead to
  3874.           distorted images.  The best way to avoid these kinds of errors is
  3875.           to allow  the creator  of an  image  to  supply  the  colorimetry
  3876.           information along with the RGB values [1] [2].
  3877.           
  3878.           The purpose  of the  colorimetry data  is to  allow a  projective
  3879.           transformation from the primaries and white point of the image to
  3880.           the primaries  and white  point of  the rendering  media.   Gamma
  3881.           reflects the non-linear transfer gradient of real media.
  3882.           
  3883.           
  3884.           IV. Colorimetric Color Reproduction
  3885.           
  3886.           Earlier we  said that given the proper colorimetric data an image
  3887.           could be  rendered identically  using  two  different  calibrated
  3888.           devices.   By identical,  we mean  colorimetric reproduction [9].
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.           TIFF 5.0                                          page 60          TIFF 5.0                                          page 60
  3899.  
  3900.  
  3901.           Specifically, the  chromaticities  match  and  the  luminance  is
  3902.           scaled to correspond to the luminance range of the output device.
  3903.           Because of this, we only need the chromaticity coordinates of the
  3904.           white point  and primaries.   The absolute luminance is arbitrary
  3905.           and unnecessary.
  3906.           
  3907.           
  3908.           V. White Point
  3909.           
  3910.           In TIFF 4.0, the white point was specified as D65.  This appendix
  3911.           allocates a  separate tag  for describing the white point and D65
  3912.           is the logical default since it is the SMPTE standard [6].
  3913.           
  3914.           The white  point is  defined  colorimetrically  in  the  CIE  xyY
  3915.           chromaticity diagram.   While  it is  rare for monitors to differ
  3916.           from D65,  scanned images  often  have  different  white  points.
  3917.           Rendered images  can have  arbitrary white  points.   The graphic
  3918.           arts use D50 as the standard viewing light source [8].
  3919.           
  3920.           
  3921.           VI. Primary Chromaticities
  3922.           
  3923.           In TIFF  4.0, the  primary color  chromaticities matched the NTSC
  3924.           specification.  With the wide variety of color scanners, monitors
  3925.           and renderers,  TIFF needs  a mechanism for accurately describing
  3926.           the chromaticities  of the  primary colors.   We use SMPTE as the
  3927.           default chromaticity  since conventional  monitors are  closer to
  3928.           SMPTE and  some monitors  (Conrac 6545)  are manufactured  to the
  3929.           SMPTE specifications.   We  donÆt use the NTSC chromaticities and
  3930.           white point  because present day monitors donÆt use them and must
  3931.           be _matrixed_ to approximate them.
  3932.           
  3933.           As an  example, the primary color chromaticities used by the Sony
  3934.           Trinatron differ  from those  recommended by  SMPTE.  In general,
  3935.           since  real  monitors  vary  from  the  industry  standards,  the
  3936.           chromaticities of  primaries are described in the CIE xyY system.
  3937.           This  allows   a  reproduction   system  to  compensate  for  the
  3938.           differences.
  3939.           
  3940.           
  3941.           VII. Color Response Curves
  3942.           
  3943.           This tag  defines three  color response curves, one each for red,
  3944.           green, and blue color information.  The width of each entry is 16
  3945.           bits, as  implied by  the type  SHORT.   The minimum intensity is
  3946.           represented by 0 and the maximum by 65535.  For example, black is
  3947.           represented by  0,0,0 and  white by  65535, 65535,  65535.    The
  3948.           length of  each curve is 2**BitsPerSample.  A ColorResponseCurves
  3949.           field for RGB data where each of the samples is 8 bits deep would
  3950.           have 3*256  entries.   The 256  red  entries  would  come  first,
  3951.           followed by 256 green entries, followed by 256 blue entries.
  3952.           
  3953.           The purpose  of the  ColorResponseCurves field  is to  act  as  a
  3954.           lookup table  mapping sample values to specific intensity values,
  3955.  
  3956.  
  3957.  
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.           TIFF 5.0                                          page 61          TIFF 5.0                                          page 61
  3965.  
  3966.  
  3967.           so that  an image  created on  one system  can  be  displayed  on
  3968.           another   with   minimal   loss   of   color   fidelity.      The
  3969.           ColorResponseCurves field thus describes the _gamma_ of an image,
  3970.           so that  a TIFF  reader on another system can compensate for both
  3971.           the image gamma and the gamma of the reading system.
  3972.           
  3973.           Gamma is  a term that relates to the typically nonlinear response
  3974.           of most  display devices,  including monitors.   In  most display
  3975.           systems, the  voltage applied to the CRT is directly proportional
  3976.           to the  value of  the red,  green, or  blue sample.  However, the
  3977.           resulting luminance  emitted by  the  phosphor  is  not  directly
  3978.           proportional to  the voltage.   This relationship is approximated
  3979.           in most displays by
  3980.           
  3981.                luminance = voltage ** gamma
  3982.           
  3983.           The NTSC  standard gamma  of 2.2 adequately describes most common
  3984.           video systems.  The standard  gamma of  2.2 implies a dim viewing
  3985.           surround.   (We know of no SMPTE recommended practice for gamma.)
  3986.           The following example uses an 8 bit sample with value of 127.
  3987.           
  3988.                voltage = 127 / 255 = 0.4980
  3989.                luminance = 0.4980 ** 2.2 = 0.2157
  3990.           
  3991.           In the  examples below,  we only  consider a  single primary  and
  3992.           therefore only a single curve.  The same analysis applies to each
  3993.           of the  red, green,  and blue  primaries and  curves.   Also, and
  3994.           without loss  of generality,  we assume that there is no hardware
  3995.           color map, so that we must alter the pixel values themselves.  If
  3996.           there is  a color  map, the  manipulations can be done on the map
  3997.           instead of on the pixels.
  3998.           
  3999.           If no  ColorResponseCurves field  exists in  a color  image,  the
  4000.           reader should  assume a  gamma of  2.2 for each of the primaries.
  4001.           This default curve can be generated with the following C code:
  4002.           
  4003.                ValuesPerSample = 1 << BitsPerSample;
  4004.                for (curve[0] = 0, i = 1; i < ValuesPerSample; i++)
  4005.                     curve[i] =  floor (pow  (i /  (ValuesPerSample -  1.0),
  4006.           2.2) * 65535.0 + .5);
  4007.           
  4008.           The displaying  or rendering  application can know its own gamma,
  4009.           which we  will call  the _destination  gamma._   (An uncalibrated
  4010.           system can usually assume that its gamma is 2.2 without going too
  4011.           far  wrong.)     Using   this  information  the  application  can
  4012.           compensate for the gamma of the image, as we shall see below.
  4013.           
  4014.           If  the  source  and  destination  systems  are  both  adequately
  4015.           described  by   a  gamma  of  2.2,  the  writer  would  omit  the
  4016.           ColorResponseCurves field,  and the  reader can  simply read  the
  4017.           image directly into the frame buffer.  If a writer writes out the
  4018.           ColorResponseCurves field,  then a  reader must  assume that  the
  4019.           gammas  differ.    A  reader  must  then  perform  the  following
  4020.           computation on each sample in the image:
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.           TIFF 5.0                                          page 62          TIFF 5.0                                          page 62
  4031.  
  4032.  
  4033.           
  4034.                NewSampleValue  =   floor  (pow   (curve[OldSampleValue]   /
  4035.           65535.0, 1.0 / DestinationGamma) *
  4036.                  (ValuesPerSample - 1.0) + .5);
  4037.           
  4038.           Of course,  if the _gamma_ of the destination system is not well-
  4039.           approximated with  an exponential  function, an  arbitrary  table
  4040.           lookup may  be used  in place  of raising  the  value  to  1.0  /
  4041.           DestinationGamma.
  4042.           
  4043.           Leave out  ColorResponseCurves if  using the default gamma.  This
  4044.           saves about  1.5K in  the  most  common  case,  and,  after  all,
  4045.           omission is the better part of compression.
  4046.           
  4047.           Do not  use this  field to  store frame  buffer color  maps.  Use
  4048.           instead   the    ColorMap   field.       Note,    however,   that
  4049.           ColorResponseCurves may  be used  to refine  the information in a
  4050.           ColorMap if desired.
  4051.           
  4052.           The above  examples assume  that a  single parameter gamma system
  4053.           adequately approximates the response characteristics of the image
  4054.           source and  destination systems.   This will usually be true, but
  4055.           our use  of a table instead of a single gamma parameter gives the
  4056.           flexibility  to  describe  more  complex  relationships,  without
  4057.           requiring additional computation or complexity.
  4058.           
  4059.           
  4060.           VIII. New Tags and Changes
  4061.           The following tags should be placed in the "Basic Fields" section
  4062.           of
  4063.           the TIFF specification:
  4064.           
  4065.           White Point
  4066.           Tag  = 318 (13E)
  4067.           Type = RATIONAL
  4068.           N    = 2
  4069.           
  4070.           The white  point of the image.  Note that this value is described
  4071.           using  the  1931  CIE  xyY  chromaticity  diagram  and  only  the
  4072.           chromaticity is  specified.  The luminance component is arbitrary
  4073.           and not  specified.   This can correspond to the white point of a
  4074.           monitor that  the image  was painted  on,  the  filter  set/light
  4075.           source combination  of a  scanner, or  to the  white point of the
  4076.           illumination model of a rendering package.
  4077.           
  4078.           Default is the SMPTE white point, D65:  x = 0.313, y = 0.329.
  4079.           
  4080.           The ordering is x, y.
  4081.           
  4082.           
  4083.           PrimaryChromaticities
  4084.           Tag  = 319 (13F)
  4085.           Type = RATIONAL
  4086.           N    = 6
  4087.  
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.           TIFF 5.0                                          page 63          TIFF 5.0                                          page 63
  4097.  
  4098.  
  4099.           
  4100.           The primary  color chromaticities.   Note  that these  values are
  4101.           described using  the 1931  CIE xyY  chromaticity diagram and only
  4102.           the chromaticities  are  specified.    For  paint  images,  these
  4103.           represent the  chromaticities of  the  monitor  and  for  scanned
  4104.           images  they   are  derived  from  the  filter  set/light  source
  4105.           combination of a scanner.
  4106.           
  4107.           Default is the SMPTE primary color chromaticities:
  4108.           
  4109.                Red: x = 0.635 y = 0.340
  4110.                Green:    x = 0.305 y = 0.595
  4111.                Blue:     x = 0.155 y = 0.070
  4112.           
  4113.           The ordering is red x, red y, green x, green y, blue x, blue y.
  4114.           
  4115.           Color Response Curves
  4116.           
  4117.           Default for  ColorResponseCurves represents  curves corresponding
  4118.           to the NTSC standard gamma of 2.2.
  4119.           
  4120.           
  4121.           IX. Defaults
  4122.           
  4123.           The defaults  used by  TIFF reflect industry standards.  Both the
  4124.           WhitePoint and  PrimaryChromaticities tags have defaults that are
  4125.           promoted  by   SMPTE  .     In  addition,  the  default  for  the
  4126.           ColorResponseCurves tag matches the NTSC specification of a gamma
  4127.           of 2.2.
  4128.           
  4129.           The purpose  of these  defaults is to allow reasonable results in
  4130.           the absence  of  accurate  colorimetry  data.    An  uncalibrated
  4131.           scanner or  paint system  produces an  image  that  be  displayed
  4132.           identically, though  probably incorrectly  on two  different  but
  4133.           calibrated systems.   This is better then the uncertain situation
  4134.           where the  image might  be rendered  differently on two different
  4135.           but calibrated systems.
  4136.           
  4137.           
  4138.           X. Limitations and Issues
  4139.           
  4140.           This section  discusses several  of the  limitations  and  issues
  4141.           involved in colorimetric reproduction.
  4142.           
  4143.           Scope of Usefulness
  4144.           
  4145.           For many  purposes the  data recommended  here is unnecessary and
  4146.           can be omitted.  For presentation graphics where there are only a
  4147.           few colors,  being able  to tell  red from green is probably good
  4148.           enough.   In this  case the  tags can  be ignored and there is no
  4149.           overhead.   In more  demanding color  reproduction  environments,
  4150.           this data  allows images to be described device independently and
  4151.           at small cost.
  4152.           
  4153.  
  4154.  
  4155.  
  4156.  
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.           TIFF 5.0                                          page 64          TIFF 5.0                                          page 64
  4163.  
  4164.  
  4165.           User Burdens
  4166.           
  4167.           The data we recommend isnÆt a user burden; it is really a systems
  4168.           issue.   It allows  a systems  solution but  doesnÆt require user
  4169.           intercession.   Calibration however  is a  separate issue.  It is
  4170.           likely to involve the user.
  4171.           
  4172.           Resolution Versus Fidelity
  4173.           
  4174.           Some manufacturers  supply greater than 24 bits of resolution for
  4175.           color specification.   The  purpose of  this is  either to  avoid
  4176.           artifacts such  as contouring  in the shadows or in some cases to
  4177.           be more  specific or  device independent  about the  color.  Both
  4178.           reasons can  be misguided.   Other, less expensive techniques can
  4179.           be used  to prevent artifacts, such as deeper color maps.  As for
  4180.           accuracy, fidelity is more important than precision.
  4181.           
  4182.           Colorimetric Color Reproduction
  4183.           
  4184.           There are other choices for objectives of color reproduction [9].
  4185.           Spectral color  reproduction is a stronger condition and most are
  4186.           weaker, such  as preferred  color  reproduction.    While  device
  4187.           independent spectral  color reproduction  is  impossible,  device
  4188.           independent  colorimetric  reproduction  is  possible,  within  a
  4189.           tolerance and within the limits of the gamuts of the devices.  By
  4190.           choosing a  strong criteria  we allow the important objectives of
  4191.           weaker criteria, such as preferred color reproduction, to be part
  4192.           of design packages.
  4193.           
  4194.           Metamerism
  4195.           
  4196.           If two  patches of  color  are  identical  under  one  light  and
  4197.           different under  another, they  are said  to be  metameric pairs.
  4198.           Colorimetric  color  reproduction  is  a  weaker  condition  than
  4199.           spectral color reproduction and hence allows metamerism problems.
  4200.           By standardizing  the viewing  conditions we  can largely finesse
  4201.           the metamerism  problem for  print.   Because television is self-
  4202.           luminous and doesnÆt use spectral absorption, metamerism isnÆt so
  4203.           much a problem.
  4204.           
  4205.           Color Models - xyY Versus Luv, etc.
  4206.           
  4207.           We choose  xyY over  Luv [1]  because XYZ  is  the  international
  4208.           standard for  color specification  and xyY  is  the  chromaticity
  4209.           diagram associated  with XYZ.   Luv is meant for color difference
  4210.           measurement.
  4211.           
  4212.           Ambient Environment And Viewing Surrounds
  4213.           
  4214.           The viewing environment affects how the eye perceives color.  The
  4215.           eye adapts  to a  dark room  and it adapts to a colored surround.
  4216.           While  these   problems  can   be  compensated   for  within  the
  4217.           colorimetric framework  [4], it is much better to finesse them by
  4218.           standardizing.   The design environment should match the intended
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.           TIFF 5.0                                          page 65          TIFF 5.0                                          page 65
  4229.  
  4230.  
  4231.           viewing environment.   Specifically it should not be a pitch dark
  4232.           room and,  on average,  it should  be of  a neutral  color.   For
  4233.           print, ANSI recommends a Munsell N-8 surface [8].
  4234.           
  4235.           
  4236.           XI. References
  4237.           
  4238.           In particular,  we would  like to mention the work of Stuart Ring
  4239.           of the  Copy Products  Division of the Eastman Kodak Company.  He
  4240.           and  his  colleagues  are  promoting  a  color  data  interchange
  4241.           paradigm.   They are  working closely  with the  ISO 8613 Working
  4242.           Group [7].
  4243.           
  4244.           [1]  Color Data  Interchange Paradigm,  Eastman Kodak, Rochester,
  4245.           New York, 7 December 1987.
  4246.           
  4247.           [2]  Color  Reproduction   and  Illumination  Models,  Roy  Hall,
  4248.           International Summer  Institute:   State of  the Art  in Computer
  4249.           Graphics, 1986.
  4250.           
  4251.           [3]  CIE   Colorimetry:    Official   Recommendations    of   the
  4252.           International Commission on Illumination, Publication 15-2, 1986.
  4253.           
  4254.           [4]  Color Science:  Concepts and  Methods, Quantitative Data and
  4255.           Formulae, Gunter  Wyszecki, W.S.  Stiles, John  Wiley  and  Sons,
  4256.           Inc., New York, New York, 1982.
  4257.           
  4258.           [5]  Color Monitor  Colorimetry, SMPTE  Recommended  Practice  RP
  4259.           145-1987.
  4260.           
  4261.           [6]  Color Temperature  for  Color  Television  Studio  Monitors,
  4262.           SMPTE Recommended Practice RP 37.
  4263.           
  4264.           [7]  Office   Document   Architecture   (ODA)   and   Interchange
  4265.           Format_Addendum on Colour, ISO 8613 Working Draft.
  4266.           
  4267.           [8]  ANSI Standard PH 2.30-1985.
  4268.           
  4269.           [9]  The Reproduction  of Colour  in  Photography,  Printing  and
  4270.           Television, R.  W. G.  Hunt, Fountain  Press, Tolworth,  England,
  4271.           1987.
  4272.           
  4273.           [10] Raster  Graphics   Handbook,  The  Conrac  Corporation,  Van
  4274.           Nostrand Reinhold  Company, New  York,  New  York,  1985.    Good
  4275.           description of gamma.
  4276.           
  4277.           
  4278.           
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.           TIFF 5.0                                          page 66          TIFF 5.0                                          page 66
  4295.  
  4296.  
  4297.           Appendix I:  Horizontal Differencing Predictor
  4298.           
  4299.           
  4300.           This appendix,  written after  the release of Revision 5.0 of the
  4301.           TIFF specification,  is still  in draft  form.   Please send  any
  4302.           comments to the Aldus Developers Desk.
  4303.           
  4304.           
  4305.           Revision 5.0  of the  TIFF specification defined a new tag called
  4306.           _Predictor_  that  describes  techniques  that  may  be  used  in
  4307.           conjuction with  TIFF compression  schemes.    We  now  define  a
  4308.           Predictor that  greatly  improves  compression  ratios  for  some
  4309.           images.
  4310.           
  4311.           The horizontal  differencing predictor  is assigned the tag value
  4312.           Predictor = 2:
  4313.           
  4314.           Predictor
  4315.           Tag  = 317 (13D)
  4316.           Type = SHORT
  4317.           N    = 1
  4318.           
  4319.           A predictor  a mathematical operator that is applied to the image
  4320.           data before  the encoding  scheme is  applied.   Currently (as of
  4321.           revision 5.0)  this tag  is used  only with  LZW  (Compression=5)
  4322.           encoding, since  LZW is  probably the  only TIFF  encoding scheme
  4323.           that benefits  significantly from a predictor step.  See Appendix
  4324.           F.
  4325.           
  4326.           1 = No prediction scheme used before coding.
  4327.           2 = Horizontal differencing. See Appendix I.
  4328.           
  4329.           Default is 1.
  4330.           
  4331.           
  4332.           The algorithm
  4333.           
  4334.           The idea  is to  make use  of the  fact that many continuous tone
  4335.           images rarely  vary much  in pixel  value from  one pixel  to the
  4336.           next.   In such  images,  if  we  replace  the  pixel  values  by
  4337.           differences between  consecutive pixels,  many of the differences
  4338.           should be  0, plus  or minus  1, and  so on.   This  reduces  the
  4339.           apparent information  content, and  thus allows LZW to encode the
  4340.           data more compactly.
  4341.           
  4342.           Assuming 8-bit  grayscale  pixels  for  the  moment,  a  basic  C
  4343.           implementation might look something like this:
  4344.           
  4345.                char image[ ][ ];
  4346.                int  row, col;
  4347.           
  4348.                /* take horizontal differences:
  4349.                 */
  4350.                for (row = 0; row < nrows; row++)
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.           TIFF 5.0                                          page 67          TIFF 5.0                                          page 67
  4361.  
  4362.  
  4363.                     for (col = ncols - 1; col >= 1; col--)
  4364.                          image[row][col] -= image[row][col-1];
  4365.           
  4366.           If we  don_t have 8-bit samples, we need to work a little harder,
  4367.           so that  we can make better use of the architecture of most CPUs.
  4368.           Suppose we  have 4-bit  samples, packed  two to a byte, in normal
  4369.           TIFF uncompressed  (i.e., Compression=1)  fashion.   In order  to
  4370.           find differences,  we want to first expand each 4-bit sample into
  4371.           an 8-bit  byte, so  that we  have one  sample per byte, low-order
  4372.           justified.   We then  perform the  above horizontal differencing.
  4373.           Once the  differencing has  been completed, we then repack the 4-
  4374.           bit differences  two to  a  byte,  in  normal  TIFF  uncompressed
  4375.           fashion.
  4376.           
  4377.           If the  samples are  greater than  8  bits  deep,  expanding  the
  4378.           samples into  16-bit words  instead of 8-bit bytes seems like the
  4379.           best way to perform the subtraction on most computers.
  4380.           
  4381.           Note that we have not lost any data up to this point, nor will we
  4382.           lose any  data later  on.   It  might  at  first  seem  that  our
  4383.           differencing might  turn 8-bit samples into 9-bit differences, 4-
  4384.           bit samples  into 5-bit differences, and so on.  But it turns out
  4385.           that we  can completely  ignore the  _overflow_  bits  caused  by
  4386.           subtracting a  larger number  from a  smaller  number  and  still
  4387.           reverse the  process  without  error.    Normal  twos  complement
  4388.           arithmetic does just what we want.  Try an example by hand if you
  4389.           need more convincing.
  4390.           
  4391.           Up  to  this  point  we  have  implicitly  assumed  that  we  are
  4392.           compressing  bilevel   or  grayscale   images.     An  additional
  4393.           consideration arises in the case of color images.
  4394.           
  4395.           If PlanarConfiguration  is 2,  there is no problem.  Differencing
  4396.           proceeds the same way as it would for grayscale data.
  4397.           
  4398.           If  PlanarConfiguration  is  1,  however,  things  get  a  little
  4399.           trickier.   If  we  didnÆt  do  anything  special,  we  would  be
  4400.           subtracting red  sample values  from green  sample values,  green
  4401.           sample values  from blue  sample values,  and blue  sample values
  4402.           from red sample values, which would not give the LZW coding stage
  4403.           much redundancy  to work  with.   So we  will do  our  horizontal
  4404.           differences with  an offset  of SamplesPerPixel  (3, in  the  RGB
  4405.           case).  In other words, we will subtract red from red, green from
  4406.           green, and  blue from blue.  The LZW coding stage is identical to
  4407.           the SamplesPerPixel=1 case.  We require that BitsPerSample be the
  4408.           same for all 3 samples.
  4409.           
  4410.           
  4411.           Results and guidelines
  4412.           
  4413.           LZW without  differencing works  well  for  1-bit  images,  4-bit
  4414.           grayscale images, and synthetic color images.  But natural 24-bit
  4415.           color images  and some 8-bit grayscale images do much better with
  4416.           differencing.  For example, our 24-bit natural test images hardly
  4417.  
  4418.  
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.           TIFF 5.0                                          page 68          TIFF 5.0                                          page 68
  4427.  
  4428.  
  4429.           compressed at  all using  _plain_ LZW:  the  average  compression
  4430.           ratio was  1.04  to  1.    The  average  compression  ratio  with
  4431.           horizontal differencing  was 1.40  to 1.  (A compression ratio of
  4432.           1.40 to 1 means that if the uncompressed image is 1.40MB in size,
  4433.           the compressed version is 1MB in size.)
  4434.           
  4435.           Although  the   combination  of   LZW  coding   with   horizontal
  4436.           differencing does  not result  in any  loss of  data, it  may  be
  4437.           worthwhile in  some situations  to give  up some  information  by
  4438.           removing as  much noise  as possible  from the  image data before
  4439.           doing the  differencing, especially  with  8-bit  samples.    The
  4440.           simplest way  to get  rid of noise is to mask off one or two low-
  4441.           order bits  of each 8-bit sample.  On our 24-bit test images, LZW
  4442.           with horizontal differencing yielded an average compression ratio
  4443.           of 1.4 to 1.  When the low-order bit was masked from each sample,
  4444.           the compression  ratio climbed to 1.8 to 1; the compression ratio
  4445.           was 2.4  to 1  when masking  two bits,  and 3.4 to 1 when masking
  4446.           three bits.   Of  course, the  more you  mask, the  more you risk
  4447.           losing useful information along with the noise.  We encourage you
  4448.           to experiment  to find  the best compromise for your device.  For
  4449.           some applications it may be useful to let the user make the final
  4450.           decision.
  4451.           
  4452.           Interestingly, most  of our RGB images compressed slightly better
  4453.           using PlanarConfiguration=1.   One  might think  that compressing
  4454.           the  red,   green,  and   blue   difference   planes   separately
  4455.           (PlanarConfiguration=2) might  give  better  compression  results
  4456.           than  mixing   the  differences   together   before   compressing
  4457.           (PlanarConfiguration=1), but this does not appear to be the case.
  4458.           
  4459.           Incidentally,  we  tried  taking  both  horizontal  and  vertical
  4460.           differences,  but   the  extra   complexity  of   two-dimensional
  4461.           differencing did  not appear  to pay  off for  most of  our  test
  4462.           images.  About one third of the images compressed slightly better
  4463.           with two-dimensional  differencing, about  one  third  compressed
  4464.           slightly worse, and the rest were about the same.
  4465.           
  4466.           
  4467.           
  4468.           
  4469.           
  4470.  
  4471.  
  4472.  
  4473.  
  4474.  
  4475.  
  4476.  
  4477.  
  4478.  
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.           TIFF 5.0                                          page 69          TIFF 5.0                                          page 69
  4493.  
  4494.  
  4495.           Appendix J:  Palette Color
  4496.           
  4497.           
  4498.           This appendix,  written after  the release of Revision 5.0 of the
  4499.           TIFF specification,  is still  in draft  form.   Please send  any
  4500.           comments to the Aldus Developers Desk.
  4501.           
  4502.           
  4503.           Revision  5.0   of  the   TIFF  specification   defined   a   new
  4504.           PhotometricInterpretation value  called _palette color._  We have
  4505.           been wondering  lately if this additional complexity is worth the
  4506.           implementation expense.   If  not, let_s  drop it before too many
  4507.           people start creating palette color images.
  4508.           
  4509.           
  4510.           The Proposal
  4511.           
  4512.           Instead of a separate palette color image type, there seems to be
  4513.           no compelling reason why palette (mapped) color images should not
  4514.           be stored as _full color_ (usually 24-bit) RGB images.
  4515.           
  4516.           
  4517.           Objections
  4518.           
  4519.           The most  obvious objection is the amount of space required.  But
  4520.           if you  care about how much space the image takes up on disk, you
  4521.           should use  LZW compression,  which is  ideally  suited  to  most
  4522.           palette color  images.   (LZW compresses  most paint-type palette
  4523.           color images  5:1 or  more.)   And if you use LZW compression, it
  4524.           turns out  that palette  color images stored as full color images
  4525.           compress to  almost exactly the same size as palette color images
  4526.           stored as  palette color  images.  That is, with LZW compression,
  4527.           there is  no penalty  for storing  palette color  images as  full
  4528.           color RGB  images.   The resulting  file may  be  a  few  percent
  4529.           larger, but  it will not be three times as large.  See Appendix F
  4530.           for more information on how LZW works.
  4531.           
  4532.           Another objection  might be  that an  application might  want  to
  4533.           process the  image differently  if it is _really_ a palette color
  4534.           image. But  we can easily add auxiliary information that can help
  4535.           a TIFF  reader to quickly categorize color images if it wants to.
  4536.           See the _New tags_ section below.
  4537.           
  4538.           
  4539.           Benefits
  4540.           
  4541.           It may  be obvious,  but it  is probably  worth discussing why we
  4542.           want  to   abolish   palette   color   images   as   a   distinct
  4543.           classification.
  4544.           
  4545.           The main  problem is  that palette color as a separate type makes
  4546.           life more  hazardous and  confusing for  users.    The  confusion
  4547.           factor is  aggravated because  users already  have to be somewhat
  4548.           aware of  distinctions  between  bilevel,  grayscale,  and  color
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.           TIFF 5.0                                          page 70          TIFF 5.0                                          page 70
  4559.  
  4560.  
  4561.           images.   Having two  main types of color images is hard for many
  4562.           users to  grasp, and  it is probably not possible to totally hide
  4563.           this complexity  from the user in certain situations.  The hazard
  4564.           level goes  up because some applications may accept palette color
  4565.           but not  full color  images, or  full color but not palette color
  4566.           images, or may accept 8-bit palette color images but not 4-bit or
  4567.           3-bit palette color images.
  4568.           
  4569.           The second  problem is  that writing and maintaining code to deal
  4570.           with an  additional image  type is  somewhat expensive  for  TIFF
  4571.           readers.  The cost of supporting palette color images will depend
  4572.           on the  application, but  we believe  that, in  general, the cost
  4573.           will be  substantial.   It seems  to make  more sense  to put the
  4574.           burden on  TIFF writers to convert palette color images into full
  4575.           color image  form than  to make TIFF readers handle an additional
  4576.           color image  type, since there are more TIFF readers than writers
  4577.           at this point.
  4578.           
  4579.           
  4580.           New tags
  4581.           
  4582.           Here are  some proposed  new tags that can help to classify color
  4583.           images, and  make up  for not  having a  separate  palette  color
  4584.           class.  They are not required for TIFF Class R , but are strongly
  4585.           recommended for  color TIFF  images created by palette-type color
  4586.           paint programs.
  4587.           
  4588.           ColorImageType
  4589.           Tag  = 318 (13E)
  4590.           Type = SHORT
  4591.           N    = 1
  4592.           
  4593.           Gives TIFF  color image  readers a  better idea  of what  kind of
  4594.           color image it is.  There will be borderline cases.
  4595.           
  4596.           1 = Continuous tone, natural image.
  4597.           2 =  Synthetic image, using a greatly restricted range of colors.
  4598.           Such images  are produced  by most  color paint  programs.    See
  4599.           ColorList for a list of colors used in this image.
  4600.           
  4601.           Default is 1.
  4602.           
  4603.           ColorList
  4604.           Tag  = 319 (13F)
  4605.           Type = BYTE or SHORT
  4606.           N    = the  number of  colors that  are used in this image, times
  4607.           SamplesPerPixel
  4608.           
  4609.           A list  of colors that are used in this image.  Use of this field
  4610.           is only  practical for  images containing  a  greatly  restricted
  4611.           (usually  less   than  or   equal  to   256)  range   of  colors.
  4612.           ColorImageType should be 2.  See ColorImageType.
  4613.           
  4614.  
  4615.  
  4616.  
  4617.  
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.           TIFF 5.0                                          page 71          TIFF 5.0                                          page 71
  4625.  
  4626.  
  4627.           The list  is organized  as an array of RGB triplets, with no pad.
  4628.           The RGB  triplets are  not guaranteed  to be  in  any  particular
  4629.           order.   Note that the red, green, and blue components can either
  4630.           be a  BYTE or  a SHORT  in length.  BYTE should be sufficient for
  4631.           most applications.
  4632.           
  4633.           No default.
  4634.           
  4635.  
  4636.  
  4637.  
  4638.  
  4639.  
  4640.  
  4641.  
  4642.  
  4643.  
  4644.  
  4645.  
  4646.  
  4647.  
  4648.  
  4649.  
  4650.  
  4651.  
  4652.  
  4653.  
  4654.  
  4655.  
  4656.  
  4657.  
  4658.  
  4659.  
  4660.  
  4661.  
  4662.  
  4663.  
  4664.  
  4665.  
  4666.  
  4667.  
  4668.  
  4669.  
  4670.  
  4671.  
  4672.  
  4673.  
  4674.  
  4675.  
  4676.  
  4677.  
  4678.  
  4679.  
  4680.  
  4681.  
  4682.  
  4683.  
  4684.  
  4685.  
  4686.  
  4687.